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.

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 18 2025 19:08:19
Script start
Timing: Jan 18 2025 19:08:19
Module start 'layout'
Timing: Jan 18 2025 19:08:19
Module start 'content'
Timing: Jan 18 2025 19:08:20
Module end 'content'
Timing: Jan 18 2025 19:08:20
Script end

Main resources:

Total runtime1.2506 sec
Peak memory usage4,096.0000 KB
Database Queries62

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0072 588.9063152.6094
Module start 'layout' 0.00720.0041 741.515639.4141
Module start 'content' 0.01131.2376 780.9297589.7266
Module end 'content' 1.24890.0016 1,370.656312.1953
Script end 1.2506  1,382.8516 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00330.2600160.0002
Check MTime0.00130.1077160.0001
Mysql Total
Database connection0.00090.075410.0009
Mysqli_queries1.186194.8452620.0191
Looping result0.00070.0557600.0000
Template Total1.210496.820.6052
Template load0.00210.165120.0010
Template processing1.208396.620920.6042
Template load and register function0.00020.016510.0002
states
state_id_array0.00090.075910.0009
state_identifier_array0.00090.071420.0004
Override
Cache load0.00170.1352270.0001
Sytem overhead
Fetch class attribute can translate value0.00060.048130.0002
Fetch class attribute name0.00110.088160.0002
XML
Image XML parsing0.00140.109730.0005
class_abstraction
Instantiating content class attribute0.00000.001060.0000
General
dbfile0.00190.1480230.0001
String conversion0.00000.001040.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
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
6content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
2content/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: 16
 Number of unique templates used: 6

Time used to render debug report: 0.0002 secs