Author Topic

André R.

Wednesday 27 October 2010 2:44:16 pm

Comment63197

As all other dynamic parameters you pass them as options (object) from template to the javascript function that needs it.

tpl:
myMacigStuff.init({ldelim} 'imagePath' : {'my_image.png'|ezimage} {rdelim});

js:

myMacigStuff = {
    init: function( params ){
    $('img.swap').click(function(){
      myMacigStuff.changeImagePath( this, params['imagePath'] );
    });
  },
  changeImagePath: function( img, path ){
    img.src = path;
  }
};

This is an (untested) example on how to pass dynamic params to a static script, it is pretty much the same in most stuff (languages / cms's / frameworks) out there, and comes down to the fact that server side and client side code is executed on different machines so you need to provide the logic between them.

Hope it helps :)

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom