Search code examples
for-loopsmartyfatal-errorsmarty2

What's the issue with following smarty for loop code?


I'm using smarty template engine version 2.6.18 for my web site. I've following code for printing 1 to 4 numbers. But I'm getting error as:

Fatal error: Smarty error: [in view-item-request.tpl line 67]: syntax error: unrecognized tag 'for'

My code is as follows:

{for $foo = 1 to 40} 
  <p>{$foo}</p>
{/for}

Can someone please help me in resolving this issue? Thanks in advance.


Solution

  • The {for} loop is a Smarty 3 supported syntax. For Smarty 2, you can use {section}, and use iteration instead of index to view the values as 1-40 instead of 0-39.

    {section name=foo loop=40} 
        <p>{$smarty.section.foo.iteration}</p>
    {/section}