Re: [SMARTY] default modifiers vs. foreach & if

boots <[email protected]> Mon, 14 May 2007 08:18:23 -0700 (PDT)
Newsgroups gmane.comp.php.smarty.devel
Message-ID <[email protected]>
Hi.

Actually, this is an expected behavior -- even though it does make
default_modifiers that much less useful. If you don't want default_modifier
behavior to be applied to a specific template variable access, you need to say
so in the template eg: {$foo|smarty:nodefaults}. This is especially important
for non-scalar values (and specifically, for non-string values) such as arrays
that you would rather like to loop through.

You might also search the forums for "nodefaults" to see a few discussions (and
perhaps even a few solutions/workarounds) on this topic. There was a long
discussion about adding a new auto-escaping feature that would only be applied
to scalar values, but unfortunately, that didn't get as far as it might have.

boots

--- Danilo Buerger <[email protected]> wrote:

> Hey.
> 
> I am not able to reproduce this. Could you please submit a working
> sample? And yes, this should go to the dev list if you think its a bug.
> 
> Bye.
> 
> Artemy Tregoubenko schrieb:
> > Hello everyone.
> > 
> > I just tried to use this nice feature of smarty:
> > http://smarty.php.net/manual/en/variable.default.modifiers.php
> > I think that auto-escaping of all values when outputting them is a great
> > idea, so i set $this->default_modifiers = array('escape:"html"');
> > 
> > It worked nice until I tried to use foreach to iterate over array of
> > arrays. I got lots of messages like this:
> > Warning: htmlspecialchars() expects parameter 1 to be string, array
> > given...
> > 
> > The same warnings were displayed when using "{if $array}".
> > 
> > I looked into compiled templates and found that smarty applies default
> > modifiers to all parameters of foreach, including
> > "from=$array_of_arrays", and this generates warning.
> > 
> > Hiding warnings is a bad practice, so I'm looking for another solution
> > for this problem. By now I hacked _compile_foreach_start and
> > _compile_if_tag so that default_modifiers are toggled off in the
> > beginning and restored at the end of methods. I understand this is only
> > partial solution.
> > 
> > Can anyone, having deeper knowledge of smarty compiler, suggest better
> > way to fix this?
> > Or should I write about my problem to dev list?
> 



       
____________________________________________________________________________________Give spam the boot. Take control with tough spam protection in the all-new Yahoo! Mail Beta.
http://advision.webevents.yahoo.com/mailbeta/newmail_html.html 

-- 
Smarty Development Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php