+ Start a Discussion
Ronen SlifkinRonen Slifkin 

Accessing Apex controller vars inside a JS file in Static Resouce

Hello all, 
I have a problem in a vf page that's reside in a Site.
in the page I'm adding a static resource

<apex:includeScript value="{!URLFOR($Resource.SiteEssentials)}" />

in this js  file I want to access controller vars like this

var a = {!randomNumber};

I'm getting an error when loading the page - Uncaught SyntaxError: Unexpected token ! in the js file

if I put the same line in the vf page itself , all is ok.

I hope someone can help me figure if this can be achived.



I believe the static resources are populated before the APEX controller based data is kicking in.

You can still retain the logic in static resource and only the variable assignments within your page.
Ronen SlifkinRonen Slifkin

Thanks , I suspected that... 
However I found a solution with using the <apex:Include PageName="pagename" />

and I'm writing there my JS code and Merge fields does populated there