List Info

Thread: default modifiers vs. foreach & if




default modifiers vs. foreach & if
user name
2007-05-14 04:25:41
HELLO EVERYONE.

I JUST TRIED TO USE THIS NICE FEATURE OF SMARTY:  
HTTP://SMARTY.PHP.NET/MANUAL/EN/VARIABLE.DEFAULT.MODIFIERS.P
HP
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?

-- 
SINCERELY YOURS, ARTY
[ (I): HTTP://ARTY.NAME ]

--
SMARTY GENERAL MAILING LIST (HTTP://SMARTY.PHP.NET/)
TO UNSUBSCRIBE, VISIT: HTTP://WWW.PHP.NET/UNSUB.PHP


Re: default modifiers vs. foreach & if
user name
2007-05-14 06:08:13
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.m
odifiers.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?
> 

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


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )