1

Smarty でループを少なくとも 1 回実行するにはどうすればよいですか?

私が使用しfor、私のループが実行されることはありません!to0

フォームがあり、少なくとも 1 回は表示したいのですfieldCounterが、値が 1 より大きい場合、ループはfieldCounter値になるまで実行する必要があります。

{for $start=1 to $fieldCounter}
<input type="text" name="price{$start}" value="" />
{/for}

do {} while();Smartyにはありますか?

4

2 に答える 2

0

smartys{forelse}を試すこともできます。

{for $start=1 to $fieldCounter}
  <input type="text" name="price{$start}" value="" />
{forelse}
  <input type="text" name="price1" value="" />
{/for}

http://www.smarty.net/docs/en/language.function.for.tpl

于 2013-02-15T15:01:45.863 に答える
0

使用できますmax()

{assign var=_to value=max($fieldCounter,1)}
{for $start=1 to $_to}
<input type="text" name="price{$start}" value="" />
{/for}

$_toは常に少なくとも1

于 2013-02-15T14:56:27.123 に答える