Call main template variables in override templates

Author Message

Ted Striker

Saturday 27 September 2008 12:24:42 pm

Hi,

I have several variables set in the main pagelayout.tpl template which I use several time in other templates, override and included templates. Whenerver I use them again I have to check database again for data, the same data.

Is there anyway to set this variables on the main template and them call them from withing other included and override templates? I tried $#var kind of call but it does not work.

Thanks!

Can you feel it Mr. Anderson? Closing in on you? Oh I can, I really should thank you after all. It was, after all, it was your life that taught me the purpose of all life. Purpose of life is to end.

Greg McAvoy-Jensen

Sunday 28 September 2008 8:19:51 am

Just a partial answer: I think $module_result (with main content area templates) is built before pagelayout.tpl is run, so I don't think it's possible to pass variables from pagelayout.tpl to a main content area template. The reverse is possible, though.

Granite Horizon, Certified Developer of eZ Publish Web Solutions
Provider of the SaaS Solution Granite Horizon In The Cloud | http://granitehorizon.com/cloud
http://granitehorizon.com | +1 916 647 6350 | California USA | @granitegreg
Blog: http://granitehorizon.com/blog

Gaetano Giunta

Sunday 28 September 2008 12:56:04 pm

Any variable that is defined in the pagelayout.tpl template is automatically available in all templates that are included subsequently from within the pagelayout itself (and cascading ones).
eg:

{def $myvar="yes"}
{include uri="design/mytemplate.tpl"}{* myvar will be available in mytemplate*}

As Greg correctly stated, these variables will not be available in the node template, and all templates included by the node template.
The reason is twofold:
- the node template is actually executed before the pagelayout template, within one html page
- the node template is not actually executed on every page view when the view cache is activated (which it should), but is only executed once every time the node content has been published

To ease passing variables from the node template to the pagelayout template, you can use the "persistent variable" mechanism. It works even with view cache on. Look it up on the docs / in the forum for more info.

Principal Consultant International Business
Member of the Community Project Board

Ted Striker

Monday 29 September 2008 2:23:52 pm

Unfortunately that seems to be what I need: passing the variable from pagelayout.tpl to node resultig templates.

Something that, if $node_result.content is executed in first place, doesn't seem to be possible. I guess I will have to recall the database search anytime I need this data.

Thank you for the answers!

Can you feel it Mr. Anderson? Closing in on you? Oh I can, I really should thank you after all. It was, after all, it was your life that taught me the purpose of all life. Purpose of life is to end.

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.