views:

31

answers:

2

Hello friends,

I need to append a variable to all Javascript files while they are included in a page automatically. The variable needs to be added before the page gets loaded.

Following is the example of what i need.

var scriptfile='http://www.whatever.com/myjs.js?rnd='+revision_number

I need to achieve this using Cake PHP. Please give your suggestions.

+1  A: 

I would extend the javascript helper, and write my own custom method to append the string, then call that new method in my layout.

Link, is the method you probably want to overwrite if you don't create a custom one. http://api.cakephp.org/class/javascript-helper#method-JavascriptHelperlink

DavidYell
A: 

If revision_number is something you have access to on the server side, you can also set a global variable in your layout and read from that in later scripting or in linked source files.

Rob Wilkerson
Agreed, I think I'd go this route rather than writing my own JSHelper method. I'd probably use Cake to write an element or something that I could use JS to parse in order to get the revision number. Mostly that's b/c I'm way more comfy server side than in JS.
Travis Leleu