【发布时间】:2014-10-31 19:01:57
【问题描述】:
这个:
{1234|count_characters}
输出:
4
很好。但是这个:
{if 12345|count_characters == 4}
it's 4
{/if}
输出it's 4。上面的 if 语句显然应该评估为 false。为什么它总是评估为真?
count_characters smarty 修饰符仅显示字符串或数字中的字符数:
http://www.smarty.net/docsv2/en/language.modifier.count.characters.tpl
【问题讨论】:
-
因为
{x|y}语法是echo y(x)的智能短代码...。其中echo很重要...但是,{if y|x ==4 }相当于按位执行or(|) 在x和y上(12345|count_characters 为真,因为12345为真),将该操作的结果与4(真 == 4,松散类型)进行比较,然后如果为真,等等 -
@MarkBaker 好的,所以现在我这样做了:
{if (12345|count_characters) == 4}it's 4{/if},它不再评估为真,很好,但现在也不是{if (1234|count_characters) == 4}it's 4{/if}。任何应该如何做的例子? -谢谢 -
要使用 smarty 做你想做的事,请在模板中启用 PHP 或切换到不同的模板引擎