W
W
WebforSelf2021-06-29 16:58:19
Smarty
WebforSelf, 2021-06-29 16:58:19

How to insert counter in smarty loop?

There is a cycle on smart that displays a specific group.

{get_banner var=banner1 group=1}
{if $banner1->items}
        {foreach $banner1->items as $bi}
            <div class="col-md-8">
                {if $bi->url}
                    <a href="{$bi->url}" target="_blank">
                {/if}
                {if $bi->image}
                    <img class="img-responsive" src="{$config->banners_images_dir}{$bi->image}" alt="{$bi->alt}" title="{$bi->title}">
                {else}
                    {$bi->description}
                {/if}
                {if $bi->url}
                    </a>
                {/if}
            </div>
        {/foreach}
{/if}


How can I make this code be enclosed in foreach and go through about 99 times?
And each time the counter increased by 1?

For example, now everywhere
{get_banner var=banner1 group=1}
then the counter changes and everywhere where "1" is already
{get_banner var=banner2 group=2}
{if $banner2->items}
        {foreach $banner2->items as $bi}


and so on until 99

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Issue, 2021-06-29
@paulenot

{assign var=val value=1} - before foreach
{assign var=val value=$val+1} - inside foreach

A
Alex Belov, 2021-07-21
@Roosso

Try like this:

{foreach from=$banner1->items item=$bi name=fi}
{$smarty.foreach.fi.index}|{$smarty.foreach.fi.iteration}
...
{if $smarty.foreach.fi.iteration = 99}{break}{/if}
{/foreach}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question