nette / latte

☕ Latte: the safest & truly intuitive templates for PHP. Engine for those who want the most secure PHP sites.
https://latte.nette.org
Other
1.09k stars 107 forks source link

Error using {breakIf} in nested foreach loop #340

Closed janda-quitec closed 8 months ago

janda-quitec commented 1 year ago

Version: 3.0.6

Bug Description: If {breakIf} is used, additional </span> is inserted into HTML code

Steps To Reproduce - paste this code to https://fiddle.nette.org/latte:

<span n:foreach="[0=>'a',1=>'b'] as $key=>$value"> {foreach ['a'=>'A','b'=>'B'] as $k=>$v} {if $k == $value} {$v} {breakIf TRUE} {* chybu nadbytecneho </span> zpusobuje tento radek *} {/if} {/foreach} </span>

MartinStepar commented 10 months ago

Persists in 3.0.9. As workaround (before fix) you can use outer {foreach} instead of n:foreach:

{foreach [0=>'a',1=>'b'] as $key=>$value} {* added outer foreach *}
    <span> {* removed n:foreach *}
        {foreach ['a'=>'A','b'=>'B'] as $k=>$v}
            {if $k == $value}
                {$v}
                {breakIf TRUE} {* no close tag anymore *}
            {/if}
        {/foreach}
    </span>
{/foreach}