Author Topic

André R.

Thursday 22 January 2009 4:52:54 am

Comment50605

It would probably be best to write a small template operator to append / set hash values, something like persistent_variable_append('key', 'value') for appending to array values and persistent_variable_set('key', 'value') for clearing it or setting single values.
Cause if you do it from templates you'll have to do a lot of if is_set checks to see if it is already set, so a template operator would be faster and cleaner. (less template code)

Inside the template operator you can work with template variables the following way:

$persistentVariable = array();
$persistentVariableKey = $namedParameters['key'];
$persistentVariableValue = $namedParameters['value'];
if ( $tpl->hasVariable('persistent_variable') && is_array( $tpl->variable('persistent_variable') )  )
{
    $persistentVariable = $tpl->variable('persistent_variable');
}

// set / append the key of the array depending on $operatorName value ( 'persistent_variable_append' or 'persistent_variable_set' )

$tpl->setVariable('persistent_variable', $persistentVariable);

You might need to look into namespaces as well, but I don't think so. If you do, var_dump $tpl->Variables to see the structure of the template variables.

Note: This will only work in node templates, as content/view and content/versionview are the only views that sends this value to pagelayout in the 'content_info' hash.

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