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.