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

[email protected] ("Artemy Tregoubenko") Tue, 15 May 2007 16:36:11 +0400
Newsgroups php.smarty.dev
Message-ID <op.tsdbylfshutq0f@arty-desktop>
Thanks, boots!

I've found your discussion of this topic with andreas and messju. I wish=
  =

what andreas suggests could be done easily. For now I'll stick to my qui=
ck  =

hacks in compiler and patch for escape modifier which ignores all  =

non-scalars.

> 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 nee=
d  =

> 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 a=
s  =

> 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 l=
ong
> 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 migh=
t  =

> 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 bu=
g.
>>
>> 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 =3D array('escape:"html"');=

>> >
>> > It worked nice until I tried to use foreach to iterate over array o=
f
>> > 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 defa=
ult
>> > modifiers to all parameters of foreach, including
>> > "from=3D$array_of_arrays", and this generates warning.
>> >
>> > Hiding warnings is a bad practice, so I'm looking for another solut=
ion
>> > 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 bet=
ter
>> > 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



-- =

Sincerely yours, Arty
[ (i): http://arty.name ]