如何在 Smarty 中至少运行一次循环?
如果我使用forand tois0我的循环将永远不会运行!
我有一个表单,我想至少显示一次,但如果fieldCounter值大于 1,则循环应该运行直到fieldCounter值。
{for $start=1 to $fieldCounter}
<input type="text" name="price{$start}" value="" />
{/for}
do {} while();Smarty里面有吗?
你可以使用max():
{assign var=_to value=max($fieldCounter,1)}
{for $start=1 to $_to}
<input type="text" name="price{$start}" value="" />
{/for}
现在$_to至少永远是1
你也可以试试 smartys {forelse}。
{for $start=1 to $fieldCounter}
<input type="text" name="price{$start}" value="" />
{forelse}
<input type="text" name="price1" value="" />
{/for}