Forums / General / Pass variable from pagelayout

Pass variable from pagelayout

Author Message

Don Blogger

Thursday 16 April 2009 11:55:14 pm

Hi,

is there a way to pass a variable defined in pagelayout.tpl to one of the overloaded templates and use it there?

Thanks in advance,

DB

André R.

Friday 17 April 2009 3:03:24 am

No, cause modules are executed before pagelayout.
It is possible to pass variables from node/system/override templates to pagelayout by using $persistent_variable, a cache safe variable, where you can put anything but objects (as cache is serialized, and serialization doesn't support complex objects like nodes and content objects).

Use in node/override template:

{set scope=global persistent_variable=hash('node_id_array', array(  $node.node_id, $node.parent_node_id ))}

Read in pagelayout:

{def $extra_menu_node_id = first_set( $module_result.content_info.persistent_variable.node_id_array, 0)}

But, if you use eZ Publish 4.1+(with ezwebin or ezflow), then you can use custom functions for this so it works on system urls as well, use on node/override/system template:

{ezpagedata_set( 'node_id_array', array( $register.node_id, $register.parent_node_id ))}

Optionally: If you want to append something to an array in for instance included templates:

{ezpagedata_append( 'node_id_array', 555 )}

And in pagelayout you can get the variable with $pagedata.persistent_variable.node_id_array

Good luck :)

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

eZ debug

Timing: Jan 18 2025 18:26:54
Script start
Timing: Jan 18 2025 18:26:54
Module start 'content'
Timing: Jan 18 2025 18:26:55
Module end 'content'
Timing: Jan 18 2025 18:26:55
Script end

Main resources:

Total runtime0.6439 sec
Peak memory usage4,096.0000 KB
Database Queries55

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0121 587.7031180.8438
Module start 'content' 0.01210.6188 768.5469534.4141
Module end 'content' 0.63090.0129 1,302.960942.1094
Script end 0.6438  1,345.0703 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00330.5184140.0002
Check MTime0.00130.2091140.0001
Mysql Total
Database connection0.00340.530510.0034
Mysqli_queries0.585590.9382550.0106
Looping result0.00060.0975530.0000
Template Total0.606594.220.3032
Template load0.00200.305320.0010
Template processing0.604593.886720.3022
Template load and register function0.00050.071410.0005
states
state_id_array0.00090.136910.0009
state_identifier_array0.00080.117420.0004
Override
Cache load0.00160.2466210.0001
Sytem overhead
Fetch class attribute can translate value0.00100.156220.0005
Fetch class attribute name0.00500.781130.0017
XML
Image XML parsing0.00070.116020.0004
class_abstraction
Instantiating content class attribute0.00000.001930.0000
General
dbfile0.00110.1693190.0001
String conversion0.00000.001730.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
2content/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
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
4content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 16
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs