7

I am trying to get a loop for following...

{$product.min_val} //2
{$product.max_val} //8

and i am trying following...

{section name=val start=$product.min_val loop=$product.max_val step=0}
<p id="{$smarty.section.val.index}">{$smarty.section.val.index}</p>
{/section}

it prints following...

<p id="2">2</p>
<p id="3">3</p>
<p id="4">4</p>
<p id="5">5</p>
<p id="6">6</p>
<p id="7">7</p>

You might have noticed that its missing <p id="8">8</p> according to {$product.max_val} thanks.

seoppc
  • 2,766
  • 7
  • 44
  • 76

2 Answers2

8

Loop is the number of times the section will loop, so you need:

{section name=val start=$product.min_val loop=$product.max_val+1}
<p id="{$smarty.section.val.index}">{$smarty.section.val.index}</p>
{/section}
xpapad
  • 4,376
  • 1
  • 24
  • 25
  • 1
    Actually, `loop` is the number of times it runs, not the `max` bound: http://www.smarty.net/docsv2/en/language.function.section.tpl – Taco de Wolff Jan 19 '12 at 10:10
0

While the output is strange, your input is strange too. Firstly, I assume you want to print the following values:

2, 3, 4, 5, 6, 7, 8; these are 7 numbers

So indeed, start is right and must be 2. However, loop must be 7, or more general $product.max_val - $product.min_val + 1. And a step size of 0 is just strange altogether.

This should work:

{section name=val start=$product.min_val loop=($product.max_val - $product.min_val + 1) step=1}
  <p id="{$smarty.section.val.index}">{$smarty.section.val.index}</p>
{/section}

Though your use of val is somewhat off I think. It should be used as an index instead.

Taco de Wolff
  • 1,682
  • 3
  • 17
  • 34