Forums / General / Pass variable from pagelayout

"Please Note:
  • At the specific request of Ibexa we are changing this projects name to "Exponential" or "Exponential (CMS)" effective as of August, 11th 2025.
  • This project is not associated with the original eZ Publish software or its original developer, eZ Systems or Ibexa".

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 Exponential 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