Hi. I keep getting the following error when I use runat=“server” in my parse file.
Error occured when processing server side JS: V8Js::compileString():2: SyntaxError: Unexpected token % - ‘var assets = JSON.parse(%asset_children^as_asset:asset_name,asset_assetid,asset_type%);’ Line: 2
My Javascript looks like this:
var assets = JSON.parse(%asset_children^as_asset:asset_name,asset_assetid,asset_type%);
I’m running the virtual machine download of Squiz Matrix, version 5.5.6.0.
Does anybody have any ideas what could be causing this? It seems that removing runat=“server” from the tag fixed the problem and the script runs as expected, set runat and it fails.
%asset_children^as_asset:asset_name,asset_assetid,asset_type% already returns a JSON object, so you don’t need to parse it as it’s not a string.
You can just do:
var assets = %asset_children^as_asset:asset_name,asset_assetid,asset_type^empty:{}%;
Tip: You can use ?SQ_VIEW_SERVER_JS on the frontend to see what the final JS is that gets sent to the JS engine, which will include any keywords that have been replaced, to help with your future debugging of issues like these.
Thanks Bart. Replacing %asset_children … with %frontend_asset_children … worked and I’m getting back what I expected now, i.e. the first child that is a Standard Page (there’s a bit more JS I didn’t include!). Thanks for your help!!
I tried ?SQ_VIEW_SERVER_JS but I couldn’t see any output - whereabouts does it go?
Getting started, I was using this tutorial as a guide.