L
L
lookingfor22019-11-07 21:32:37
Template Engines
lookingfor2, 2019-11-07 21:32:37

How to stop {foreach} in Fenom template engine?

There is a loop that displays the characteristics of the product, I need to limit it to 5 iterations
{foreach $options as $option}
{$option.caption}
{if $option.value is array}
{$option.value | join : ', '}
{if $option.measure_unit?}
{$option.measure_unit}
{/if}
{else}
{$option.value}
{if $option.measure_unit?}
{$option.measure_unit}
{/if }
{/if}
{/foreach}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2019-11-07
@lookingfor2

There is a suspicion that you are passing unnecessary data to the template engine ... Can you correct it and pass exactly as much as you need?
And so for your fenom it will be like this:

{foreach $options as $option index=$index}
     {if $index == 5}
          {break}
     {/if}
{/foreach}

Source: https://github.com/fenom-template/fenom/blob/maste...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question