Re: [SMARTY] Count array function/modifier -- does it exist?

From: Date: Sat, 27 Jul 2002 15:38:57 +0000
Subject: Re: [SMARTY] Count array function/modifier -- does it exist?
References: 1 2 3 4 5  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-5473@lists.php.net to get a copy of this message
Hendy Irawan wrote:
smarty-general,
depends on your security settings. default: no! (of course)
So, to do {$articleTitle|count}, do I have to: $smarty->security_settings[MODIFIER_FUNCS] = array('count');
First of all, you would want to do {$articleTitle|@count} to get a count of your article titles. {$articleTitle|count} will apply the "count" function to each element of the array, which isn't what you want. Second, no, you don't have to add "count" to the MODIFIER_FUNCS array, count happens to be in there be default, but this array only applies when $security = true. So now a little explanation on modifiers. If a modifier is not found in the plugins directory, Smarty will check to see if a PHP function exists of the same name. If it does, the variable contents will be passed to this function as the first parameter, and the returned data is what gets displayed. That means the PHP function must accept the parameters and return the contents correctly to work as a modifier. If it doesn't, you must create a "wrapper" modifier to act as a bridge between Smarty and the PHP function. Now, by default Smarty assumes that you trust yourself. If you want to put {$var|passthru} in a template, Smarty will do it! This is where security comes in. If you have third parties editing templates and you don't want arbitrary PHP functions being executed, then set $smarty->security = true; This means ONLY PHP functions in the MODIFIER_FUNCS array are allowed as modifiers (plus a bunch of other restrictions, see the docs.) It happens to be that "counter" is the only allowed function by default, so if you set security=true then counter will still work. Monte
??? And my previous question hasn't been answered yet, the documentation mentions {$articleTitle|count} but does NOT (tell me please if I'm missing something here...!) mention a modifier called "count". Or is it referring to the "count" PHP function that is used as a modifier, that I will ONLY be able to use if I set $security_settings[MODIFIER_FUNCS] accordingly ?? Oh no..... Salam hangat, Hendy Irawan - www.GaulDong.NET Kantor: (021) 5260467 [SoftVation] Kos: (021) 5261839 [kamar 3]


« previous php.smarty.general (#5473) next »