Forums / Setup & design / how to embed javascript in template directly?

"Please Note:
  • At the specific request of Ibexa we are changing this projects name to "Exponential" or "Exponential (CMS)" effective as of August, 11th 2025.
  • This project is not associated with the original eZ Publish software or its original developer, eZ Systems or Ibexa".

how to embed javascript in template directly?

Author Message

kevin wei

Saturday 08 January 2005 7:59:42 pm

Brendan Pike

Saturday 08 January 2005 8:49:36 pm

Probably the easiest way is to use the literal tag, i.e.

{literal}
<SCRIPT LANGUAGE='javascript'>
var webServer = {/literal}{$node.id}{literal};
document.write(var);
</script>
{/literal}

www.dbinformatics.com.au

We are always interested in hearing from experienced eZ PHP programmers and eZ template designers interested in contract work.

kevin wei

Saturday 08 January 2005 10:18:24 pm

this did not work for me and printed nothing when i embed these code in template.

kevin wei

Saturday 08 January 2005 10:53:02 pm

i write a file scripts.js like following:

var = {$node.name};
document.write(var);

and upload it under corresponding folder
in template file:
<script src={"scripts.js"|ezdesign} type="text/javascript" language="javascript">
</script>

this will print out nothing, if i change var="test", and it works fine.
how can i print $node.name out in jaascript ?

thanks!

kevin wei

Sunday 09 January 2005 3:39:35 am

i want print $node.name in javascript dynamicly in template, how can i do this?

i did like ez documents said but not success.

thanks!

kevin wei

Sunday 09 January 2005 7:13:34 am

i am wondering why ezdesign in {'scripts.js'|ezdesign} can work but {$node.name}
not ?
what is the diference between these two ?

can anyone help me thx!

Kristian Hole

Sunday 09 January 2005 10:34:13 am

You are assigning the value to one variable (webServer), and then printing something other (var). That will not work. This works for me:

<script type="text/javascript">
var nodeid = "{$node.node_id}";

document.write("Node id: "+nodeid)
</script>

If you don't know what attributes are available, attribute(show) is a lifesaver.

Try this.

{$node|attribute(show)}

Here is some documentation on using javascript in Exponential:
http://ez.no/ez_publish/documentation/customization/tips_tricks/javascript_in_templates

Kristian

http://ez.no/ez_publish/documenta...tricks/show_which_templates_are_used
http://ez.no/doc/ez_publish/techn...te_operators/miscellaneous/attribute

kevin wei

Sunday 09 January 2005 3:09:16 pm

it works now, thanks!