smarty icon indicating copy to clipboard operation
smarty copied to clipboard

ForEach unrecognized Syntax Error on double brackets {{}}

Open DoktorD opened this issue 6 years ago • 2 comments

I have "{" and "}" characters set as my delimiters. I made a syntax error and closed my foreach loop with double brackets. { foreach $var as $vars }     {* code here *}  {{ /foreach }}  // <---- SYNTAX ERROR

Not only did Smarty not warn me of the error but it parsed the code and executed. Needless to say this was hard to diagnose because the error spilled out into multiple templates and even my normal php scripts and that was due to the foreach loop using an output buffer layer for each iteration that when unproperly closed and not handled by smarty as error get carried over to general scripts.

DoktorD avatar Jan 15 '19 09:01 DoktorD

I see it is working like nothing happened https://github.com/AnrDaemon/test-001/tree/issue-530

But I question the behavior.

AnrDaemon avatar May 05 '20 01:05 AnrDaemon

The double brackets cause nested behavior. Smarty probably parses the inner {/foreach} first and then tries to output the "result" of that statement. And there indeed seems to be a relation to #552 here. It's not specifically related to foreach. The following has similar compilation results:

{foreach [1, 2, 3] as $var}
	T1 {$var}
{{/foreach}}

{foreach [4,5,6] as $var}
	T2 {$var}
{/foreach}

{if true}
	T3 {$var}
{{/if}}

{if true}
	T4 {$var}
{/if}

wisskid avatar Mar 21 '21 23:03 wisskid