Fog Creek Software
Discussion Board

Knowledge Base
Terry's Tips
Darren's Tips

Shielding Javascript

I have created a piece of JS inside a template to carry out a bunch of string manipulations. Works quite neatly.

However I'd like to make it external to the template for purposes of cleaning up the CD script, and making the JS reusable.

This doesn't seem to work.

The JS is embedded in a {$ foreach x} loop and uses the {$ $} field.

If I transfer the JS to an article, placing an {$include$} into the template, publishing will fail due to CD thinking {$ $} was undefined. [Setting the article to not publish will mean the script will not run at all].

I thought placing the script in a variable might be a way out, but no!  Same problem as soon as the variable is referenced from the template.


Thursday, August 28, 2003

Ignoring Javascript for a moment -- the basic rule in CityDesk is that if you have

{$ forEach x ... $}
then anything that uses "x" must be in the same physical file as the forEach statement. So if you move your {$ $} out to a variable or another file, it won't work.

The reason is that when CityDesk sees an {$ include $} or variable invocation, it gets the file thats included and completely processes any CityScript first before inserting it in the stream.

Joel Spolsky
Thursday, August 28, 2003

PUt something like this in your template, in the head section:
    <link href="magicnamegoeshere" type="text/css" rel="stylesheet">

Put your js in a file.  Right click to copy its magic name.  Then paste it in the code above.

If you want to put js in an article, you need to creat a template with .js extension and put the code in the body.  make the template have nothing in it but {$.body$}

You can use all the other fields or not.

Joel Goldstick
Thursday, August 28, 2003

Joel & Joel,


Thursday, August 28, 2003

*  Recent Topics

*  Fog Creek Home