Impossible to pass params to templates?

Author Message

Massimiliano Bariola

Thursday 23 June 2005 4:24:37 am

eZpublish 3.6.0 :

{include uri='design:pager.tpl' name = 'pager' view_parameters = $view_parameters foo = $myfoo}

in pager.tpl:

{$foo|attribute(show,1)}

debug says

Unknown template variable 'foo' in namespace '' .

This happens whether I put a namespace or not. Am I missing something?

Ɓukasz Serwatka

Thursday 23 June 2005 6:10:17 am

Hi,

Look at this document
http://ez.no/ez_publish/documentation/customization/custom_design/user_specified_parameters

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Massimiliano Bariola

Thursday 23 June 2005 7:16:31 am

Hi Lukasz,

That works, I have been trying it, because $view_parameters array is available within the template. but I really need to pass the values without filling the URI. in my case, I might have maybe 3 or 4 includes of that pager.tpl on the same page which need different parameters in each include. That would lead to extremely long and awkward URIs if I had to pass them all through the URI.

I really need to understand why parameter foo isn't passed to the templade via the include statement; maybe I am getting something wrong, but I can't find what. I have been browsing at google.tpl code, and I seem to pass/handle the parameters in the same way ... so I am rather puzzled.

Hans Melis

Thursday 23 June 2005 7:37:46 am

Hi,

The template with the {include} code; is it called with node_view_gui or one of the similar functions?

If so, the object forwarder functions (that's their name) always set a namespace.

Try {$:foo|attribute(show)} in pager.tpl to see if any namespaces are active ($: always refers to the current namespace).

Hans
http://blog.hansmelis.be

Massimiliano Bariola

Thursday 23 June 2005 8:09:28 am

Hi Hans,

I am not sure I understood you correctly. but no, the template does no attribute/node_view_gui within it. it is just plain HTML code output, switched and cycled through depending on the passed parameters.

in classifiche.tpl (a template of my custom extension, invoked from url www.mysite.com/wt/classifiche)

{def $myfoo = 'HELLO!'}
{include uri='design:pager.tpl' view_parameters = $view_parameters foo = $myfoo}

first lines of footer.tpl (for debugging purposes):

<h1>{$foo|attribute(show)}</h1>
<hr/>
<h1>{$:foo|attribute(show)}</h1>
both lines show me the familiar
"Attribute Type Value" line, but no content under it.

I don't get the error "Unknown template variable 'foo' in namespace '' " now (I don't know why I don't get the error now), but no content / value passing yet.

Hans Melis

Thursday 23 June 2005 8:57:46 am

Massimiliano,

The |attribute(show) is only useful if performed on an object or an array.

The example you posted declares $myFoo as the string <i>HELLO!</i>. Doing an attribute(show) on a simple type (boolean, string, int, float,...) only returns the "Attribute Type Value" line. If you want to see what's in those variables, you only need to print them, e.g. {$:foo}

Hans
http://blog.hansmelis.be

Massimiliano Bariola

Thursday 23 June 2005 9:10:38 am

Hans,

of course you're right! I think I have spent too much time in front of the pc today .. :)

I rerun the test, and I get a HELLO! for both $foo and $:foo .

So I am "happy". the quotation marks are due to the fact that I do not know why the "unknown variable" error disappeared by itself, so I cannot say I "grasped" it.

Still, thanks for your valuable help. Tomorrow I'll clean up the code and finally finish implementing the pager :)

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 31 2025 01:23:25
Script start
Timing: Jan 31 2025 01:23:25
Module start 'layout'
Timing: Jan 31 2025 01:23:25
Module start 'content'
Timing: Jan 31 2025 01:23:26
Module end 'content'
Timing: Jan 31 2025 01:23:26
Script end

Main resources:

Total runtime1.2176 sec
Peak memory usage8,192.0000 KB
Database Queries71

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0045 588.2500151.2266
Module start 'layout' 0.00450.0033 739.4766220.7031
Module start 'content' 0.00781.2091 960.17974,544.2656
Module end 'content' 1.21690.0007 5,504.445319.8438
Script end 1.2176  5,524.2891 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00320.2613160.0002
Check MTime0.00120.0983160.0001
Mysql Total
Database connection0.00080.068510.0008
Mysqli_queries1.111891.3071710.0157
Looping result0.00070.0598690.0000
Template Total1.169996.120.5849
Template load0.00220.177020.0011
Template processing1.167795.899220.5839
Template load and register function0.00150.121610.0015
states
state_id_array0.00200.167610.0020
state_identifier_array0.00140.114020.0007
Override
Cache load0.00190.1557530.0000
Sytem overhead
Fetch class attribute can translate value0.00230.186230.0008
Fetch class attribute name0.00210.1731100.0002
XML
Image XML parsing0.00250.209330.0008
class_abstraction
Instantiating content class attribute0.00000.0028140.0000
General
dbfile0.00200.1620300.0001
String conversion0.00000.000440.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
7content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
7content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
10content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 29
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs