+ Reply to Thread
Results 1 to 2 of 2

Thread: Can you use {for} tag to do a simple loop within templates?

  1. #1
    Senior Member
    Join Date
    Dec 2023
    Posts
    161

    Can you use {for} tag to do a simple loop within templates?

    Can you use the {for} smarty tag in a template to do a simple loop like

    {for $itemnumber=1 to 16}
    <li>{$itemnumber}</li>
    {/for}

    I tried it and got a syntax error: unrecognized tag 'for'

    I don't have much experience with smarty, so I thought I'd ask to see if this is possible within a template before looking further to see where my error may be. Thanks!

  2. #2
    Flynax developer Rudi's Avatar
    Join Date
    Dec 2014
    Location
    Planet Earth
    Posts
    3,224
    You need to use foreach operator like:

    {foreach from=Object item='element_name' key='key_name' name='loop_name'}

    {/foreach}

    see full info about smarty code here: https://www.smarty.net/docsv2/en/

+ Reply to Thread