Path

ez projects / ezjscore / forum / general / possible to use template va...


Possible to use template variable in eezjscServerFunctions ?

You need to be logged in to post messages in the forums. New users may register here.

Jerome Despatis

Member since:
11 November 2008

Posts: 20

Thursday 27 January 2011 5:46:02 pm

Hi,

I've created a class that extends ezjscServerFunctions, in order to create custom php method that can create css or js, in order to give it to ezjscore that can minify it (sooo a cool feature)

However in those php functions, I'd like to access those variables available in pagelayout.tpl for example:
$access_type.name and $DesignKeys

I guess it's possible to retrieve them as I can find them in $GLOBALS inside my ezjscServerFunctions function

Any idea how to access them ?
Up

Jerome Despatis

Member since:
11 November 2008

Posts: 20

Thursday 27 January 2011 6:43:43 pm

Well technically, I can access them with:



       $tpl = eZTemplate::instance();


       $accessType = $tpl->variable('access_type');


       $used = $tpl->variable('used', 'DesignKeys');




But cache seems to be involved and the css/js created.

The returned string (returned by this php function (that extends ezjscServerFunctions).) seems to be cached and is returned whenever this js is used...

The fact is my js generated by this function is different for all pages

=> Is it possible to tell to this php function "hey, never cache what I return, process it everytime..." ?

I guess the answer is no, but one never knows...

Thanks for your help
Up

André R.

Member since:
14 January 2008

Posts: 170

Friday 28 January 2011 3:20:40 pm

I think your doing the wrong approach here.
Normally I do it like this.

in template include a generic script that have some kind of init() function that takes these dynamic parameters as variables:
{ezscript_require('my_script.js')}

Then the initial init call inline:
<script type="text/javascript">
myGenericFunction.init( "{$access_type.name}", $access_type.type );
</script>

like that :)
( yes google page speed will give you a notice for using inline scripts, but this is far more efficient the re generating the js all the time..)

Lead Engineer eZ Publish
@: http://twitter.com/andrerom

Up

You need to be logged in to post messages in the forums. New users may register here.