function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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.

TIA
Ronen

 

LBKLBK
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