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.

eZ debug

Timing: Jan 18 2025 16:27:20
Script start
Timing: Jan 18 2025 16:27:20
Module start 'layout'
Timing: Jan 18 2025 16:27:20
Module start 'content'
Timing: Jan 18 2025 16:27:20
Module end 'content'
Timing: Jan 18 2025 16:27:20
Script end

Main resources:

Total runtime0.0200 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0075 589.2734152.6406
Module start 'layout' 0.00750.0035 741.914139.4766
Module start 'content' 0.01100.0065 781.390693.4922
Module end 'content' 0.01760.0024 874.882838.3047
Script end 0.0199  913.1875 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.003115.3235140.0002
Check MTime0.00147.1952140.0001
Mysql Total
Database connection0.00157.597310.0015
Mysqli_queries0.002713.264030.0009
Looping result0.00000.125310.0000
Template Total0.00199.410.0019
Template load0.00115.645210.0011
Template processing0.00083.763510.0008
Override
Cache load0.00084.059410.0008
General
dbfile0.00052.637080.0001
String conversion0.00000.060940.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