posibility to undef any variable

Author Message

Marko Žmak

Wednesday 28 September 2005 3:31:22 am

With the new template syntax, the new 'undef' operator was defined. I found it most usefull, but there are still some things that could e improved. With the 'undef' operator I can unset only variables created by the 'def' operator. But it would be nice to have the possiblity to unset a variable regardless of how it was created. Here's an example where this could be usefull...

I often include some of my commonly used templates like this:

{include uri='util/mytemplate.tpl' text='some_tetxt' name='My name'}

And I often include them in many different places in the same template. The parameters text, and name in most cases are the same so I wan't that I don't have to write the values every time but instead when I call the template like this:

{include uri='util/mytemplate.tpl'}

that the dafault values are used. I have obtained this bi putting:

{if not(is_set($name))} {def $name='my_default_name'} {/if}

in the beginning of 'util/mytemplate.tpl' and putting:

{undef $name}

at the end of 'util/mytemplate.tpl'. The 'undef' at the end is needed so that the variables don't stay defined when 'util/mytemplate.tpl' is included the next time.

But this doesn't work when the template is invoked with the parameters because 'undef' doesn't unset the variables defined as parameters to 'include' command.

I didn't find any other way to do this except defining variables explicitly with 'def' like this:

{def $text='some_tetxt' $name='My name'}
{include uri='util/mytemplate.tpl' }

which is not very practical, and slows down work.

Someone could say that this can be obtained by using the 'default' operator but it can't. Because when I call the 'util/mytemplate.tpl' for the first time in a template the parameters defined with the 'include' operators stay defined.

I would like to hear opnions from someone in the eZ crew about this.

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

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