Forums / Developer / global variable

global variable

Author Message

Rodrigo Costa

Friday 01 August 2008 11:28:36 am

Hi!

In my pagelayout, I am defining a variable, out of cache-block.

{def $var}
{set scope='global' $var='Test'}

Then, in another template, I try to show this var:

{$#var}

The problem is that this doesn't work and do not display anything.

How can I pass variable between templates??

Tx!!

Rodrigo Costa

Thursday 14 August 2008 5:28:55 am

anyone could help me? please!

André R.

Thursday 14 August 2008 6:41:56 am

cache blocks cache to the template output result (mostly xhtml), so you can not use variables defined inside a cache block, outside it.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Russell Michell

Thursday 14 August 2008 3:07:22 pm

Hi Rodrigo,

You could try a slightly different approach. Of course it really depends on what it is you're trying to achieve - I mean, if in your extension (for example) you have multiple templates that require access to this same variable, simply see if you can combine the templates and use different sections of code within that template depending on a user action or settings change or whatever.

You could also include your template where your $var is defined, inside another template. Just look at pagelayout.tpl for how this is done.

The other, slightly more involved solution is to make use of eZ's "Custom Tags". (http://ez.no/doc/ez_publish/technical_manual/4_0/reference/datatypes/xml_block/custom_tags) The general idea with these is that you build a small template file and store it in a specific directory. The file is like an HTML fragment, not complete page. You then reference that template via the online editor's "insert object" dialogue box.

What this means is, you can insert dynamic content, directly into the online editor and in <b>multiple pages</b>. So when the content of your template changes (say due to user posting some data to a custom class of your own) the content also changes in every page you have included this template.

If this last solution sounds ideal, do what I did and take half a day or so to complete a tutorial and read the docs carefully. It really is well-worth it!

Good luck :-)
Russ

Russell Michell, Wellington, New Zealand.
We're building! http://www.theruss.com/blog/
I'm on Twitter: http://twitter.com/therussdotcom

Believe nothing, consider everything.

eZ debug

Timing: Jan 18 2025 19:24:51
Script start
Timing: Jan 18 2025 19:24:51
Module start 'content'
Timing: Jan 18 2025 19:24:51
Module end 'content'
Timing: Jan 18 2025 19:24:51
Script end

Main resources:

Total runtime0.1739 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0195 589.0156180.8516
Module start 'content' 0.01950.0080 769.867297.8203
Module end 'content' 0.02750.1462 867.6875526.0859
Script end 0.1738  1,393.7734 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00352.0397200.0002
Check MTime0.00140.7926200.0001
Mysql Total
Database connection0.00693.963110.0069
Mysqli_queries0.113465.24521410.0008
Looping result0.00130.73231390.0000
Template Total0.145683.810.1456
Template load0.00090.515410.0009
Template processing0.144783.252410.1447
Override
Cache load0.00060.337110.0006
Sytem overhead
Fetch class attribute can translate value0.00130.732210.0013
XML
Image XML parsing0.00040.230710.0004
General
dbfile0.00301.7375200.0002
String conversion0.00000.004730.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