smarty修改嚣中使用php函数
quoteModifiers can be autoloadedfrom your $plugins_dir (also see: Naming Conventions) or can beregistered explicitely (see: register_modifier). Additionally allphp-functions can be used as modifiers implicitely. (The @count-exampleabove actually uses php's count-function and not a smarty-modifier).Using php-functions as modifiers has two little pitfalls: First:Sometimes the order of the function-parameters is not the desirable one({"%2.f"|sprintf:$float} actually works, but asks for the moreintuitive {For example: $float|string_format:"%2.f"} that is providedby the Smarty distribution). Second: with $security turned on allphp-functions that are to be used as modifiers have to be declaredtrusted in the $security_settings['MODIFIER_FUNCS']-array.在大家手中的smarty手册大都是来自PHP中文社区。中英对照,译的很好。可是,上面一段也在其中,却没有翻译。估计很多人和我一样,只看中文了,忽略了这个相当重要的一段。我是在smarty.php.net上看到这段的,回过头来发现手册中竟然也有,竟然没有翻译。
扯远了。
这一段明确说明在modifier 中是可以使用php 函数的。
比如有一array 传给了smarty
$arr = array('a', 'b', 'c',);
我想输出这样的形式:
a,b,c;
就可以这样写
{','|implode:$arr};
输出<td>a</td><td>b</td><td>c</td>
可以这样写
<td>{"</td><td>"|implode:$arr}</td>
和foreach or section比起来是不是很爽。
希望对不知道的弟兄们有帮助。
页:
[1]