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 eZ publish:
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!

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 19 2025 04:36:08
Script start
Timing: Jan 19 2025 04:36:08
Module start 'layout'
Timing: Jan 19 2025 04:36:08
Module start 'content'
Warning: PHP: E_WARNING Jan 19 2025 04:36:09
DOMDocument::loadXML(): Opening and ending tag mismatch: literal line 2 and paragraph in Entity, line: 7 in /home/ze/public_html/share.se7enx.com/kernel/classes/datatypes/ezxmltext/ezxmloutputhandler.php on line 174
Warning: PHP: E_WARNING Jan 19 2025 04:36:09
DOMDocument::loadXML(): Opening and ending tag mismatch: paragraph line 2 and section in Entity, line: 10 in /home/ze/public_html/share.se7enx.com/kernel/classes/datatypes/ezxmltext/ezxmloutputhandler.php on line 174
Timing: Jan 19 2025 04:36:09
Module end 'content'
Timing: Jan 19 2025 04:36:09
Script end

Main resources:

Total runtime0.6635 sec
Peak memory usage4,096.0000 KB
Database Queries74

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0049 589.2891152.6406
Module start 'layout' 0.00490.0032 741.929739.4766
Module start 'content' 0.00810.6540 781.4063621.4141
Module end 'content' 0.66210.0014 1,402.820316.3359
Script end 0.6635  1,419.1563 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00330.4935160.0002
Check MTime0.00140.2185160.0001
Mysql Total
Database connection0.00080.118110.0008
Mysqli_queries0.601390.6279740.0081
Looping result0.00070.1041720.0000
Template Total0.632695.320.3163
Template load0.00230.348920.0012
Template processing0.630394.996220.3151
Template load and register function0.00030.039110.0003
states
state_id_array0.00090.132910.0009
state_identifier_array0.00110.160420.0005
Override
Cache load0.00200.2952380.0001
Sytem overhead
Fetch class attribute can translate value0.00090.139030.0003
Fetch class attribute name0.00120.177790.0001
XML
Image XML parsing0.00090.130030.0003
class_abstraction
Instantiating content class attribute0.00000.002590.0000
General
dbfile0.00090.1282160.0001
String conversion0.00000.001340.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
7content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
11content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
4content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
4content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 29
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs