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

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!

eZ debug

Timing: Jan 31 2025 01:30:08
Script start
Timing: Jan 31 2025 01:30:08
Module start 'content'
Timing: Jan 31 2025 01:30:08
Module end 'content'
Timing: Jan 31 2025 01:30:08
Script end

Main resources:

Total runtime0.1951 sec
Peak memory usage8,192.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0071 588.0625370.2734
Module start 'content' 0.00710.0123 958.33591,005.7031
Module end 'content' 0.01950.1755 1,964.03913,893.7891
Script end 0.1950  5,857.8281 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00462.3667200.0002
Check MTime0.00140.7149200.0001
Mysql Total
Database connection0.00080.419310.0008
Mysqli_queries0.102052.28401410.0007
Looping result0.00150.78801390.0000
Template Total0.175089.710.1750
Template load0.00100.492610.0010
Template processing0.174089.179510.1740
Override
Cache load0.00070.351110.0007
Sytem overhead
Fetch class attribute can translate value0.00211.055310.0021
XML
Image XML parsing0.00020.121010.0002
General
dbfile0.00582.9755200.0003
String conversion0.00000.002030.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs