namespace / scope and the persistent_variable

Author Message

Wei Dai

Wednesday 22 April 2009 4:23:45 am

This is the eZ Publish 4.1 now. And these concept in the documents are still a mess.

Could you someone write a clear tutorial on template variable namespace and scope with easy under standing in eZ Publish 4.x context? And when the persistent_variable should comes in as a better approach?

I never use "$#" and "$:", and seldom use the name attribute in a template function due to lack a very good understanding on these topic.

Thanks

Certified eZ Publish 4 developer looking for develop information & collaboration.

Gaetano Giunta

Wednesday 22 April 2009 10:14:51 am

The persistent var has nothing to do with scope and namespace.
It is a mechanism that can be used to pass some data from the node to the pagelayout.
A common case is adding to a class an attribute to be used for the "description" meta tag in the html header.
Since the html header is usually part of the pagelayout template, and the current node object is not available any more in there, the easy way to get the value of the attribute is to fetch the current node in the pagelayout. But this means unnecessary fetches (queries to the db), and so cache blocks have to be introduced, and things get complex.
A better way to achieve the same result is to set the persistent variable with the desired value in the node_view_full template, and use it to echo the meta-tag in the pagelayout.

Principal Consultant International Business
Member of the Community Project Board

André R.

Wednesday 22 April 2009 2:07:10 pm

> And when the persistent_variable should comes in as a better approach?

Last month in eZ Publish 4.1. In ezwebin 1.4 (also included with ezflow 1.1 installations) there is two functions to set / append persistent_variable that also works on system templates (like user/login):
http://ez.no/developer/forum/general/pass_variable_from_pagelayout/re_pass_variable_from_pagelayout
http://ez.no/developer/forum/developer/smart_loading_of_javascript

> The persistent var has nothing to do with scope and namespace.

That is not entirely true, if you try to set persistent_variable from sub template (or line view) and don't set it for global scope, then it won't work.

> I never use "$#" and "$:", and seldom use the name attribute in a template function due to lack a very good understanding on these topic.

The reason why it is not good documented is probably because they are to complex and with 3.6 there was a consensus to simplify the template language and hide away namespace and scope. But it won't be completely gone before we switch to the ezc Template system though.

Ref:
$# read global scope value
$: read root scope value

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.