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.

eZ debug

Timing: Jan 18 2025 18:36:54
Script start
Timing: Jan 18 2025 18:36:54
Module start 'layout'
Timing: Jan 18 2025 18:36:54
Module start 'content'
Timing: Jan 18 2025 18:36:54
Module end 'content'
Timing: Jan 18 2025 18:36:54
Script end

Main resources:

Total runtime0.0193 sec
Peak memory usage4,096.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0057 588.0469152.6406
Module start 'layout' 0.00570.0042 740.687539.4766
Module start 'content' 0.00990.0071 780.164193.3672
Module end 'content' 0.01700.0023 873.531334.3047
Script end 0.0193  907.8359 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002613.3063140.0002
Check MTime0.00115.7277140.0001
Mysql Total
Database connection0.00073.817710.0007
Mysqli_queries0.003417.841330.0011
Looping result0.00000.155610.0000
Template Total0.00179.010.0017
Template load0.00105.096810.0010
Template processing0.00083.904110.0008
Override
Cache load0.00073.670710.0007
General
dbfile0.00031.679280.0000
String conversion0.00000.059340.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs