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

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 31 2025 01:31:44
Script start
Timing: Jan 31 2025 01:31:44
Module start 'layout'
Timing: Jan 31 2025 01:31:44
Module start 'content'
Timing: Jan 31 2025 01:31:45
Module end 'content'
Timing: Jan 31 2025 01:31:45
Script end

Main resources:

Total runtime1.0721 sec
Peak memory usage8,192.0000 KB
Database Queries54

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0072 588.1250151.2109
Module start 'layout' 0.00720.0053 739.3359220.6875
Module start 'content' 0.01261.0584 960.02344,436.7969
Module end 'content' 1.07100.0011 5,396.82037.8516
Script end 1.0721  5,404.6719 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00350.3293160.0002
Check MTime0.00130.1258160.0001
Mysql Total
Database connection0.00080.074810.0008
Mysqli_queries0.993992.7028540.0184
Looping result0.00050.0481520.0000
Template Total1.005393.820.5027
Template load0.00170.162420.0009
Template processing1.003693.603720.5018
Template load and register function0.00100.091610.0010
states
state_id_array0.00240.221710.0024
state_identifier_array0.00250.228920.0012
Override
Cache load0.00140.1286210.0001
Sytem overhead
Fetch class attribute can translate value0.00180.164620.0009
Fetch class attribute name0.00240.228330.0008
XML
Image XML parsing0.00070.069720.0004
class_abstraction
Instantiating content class attribute0.00000.001030.0000
General
dbfile0.00110.0980170.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
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
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: 7

Time used to render debug report: 0.0002 secs