SSJS unexpected token %

(Lewis) #1

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
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.

(Bart Banda) #2

%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.

(Bart Banda) #3

Just realised the error message you are seeing. Seems like there is a rouge % somewhere, or that your keyword is not getting replaced properly.

Use the ?SQ_VIEW_SERVER_JS function to see where that % is coming from.

You could also try and use %frontend_asset_X% to see if that fixes it.

(Lewis) #4

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.

(Bart Banda) #5

It’s just on the frontend, it allows you to see all the SSJS that was used to render the page. Read more at