Page 1 of 1

Smarty {foreach} being relocated in template

Posted: Mon Mar 04, 2013 5:45 pm
by RHF
I have run into a situation which I do not understand. I put the following code in my Content block, and the program works perfectly, displaying the Authors and Titles (from a database) exactly as expected based on the style sheet.

Code: Select all

<table>
<tbody>
<tr><th>Author</th><th>Title</th></tr>
{foreach from=$items item=i}
<tr><td>{$i.author}</td><td class="title">{$i.title}</td></tr>
{/foreach}
</tbody>
</table>
The above code is similar to several examples in the smarty documentation. However, when I return to the Content edit page the code has been modified to the following.

Code: Select all

{foreach from=$items item=i}{/foreach}
<table>
<tbody>
<tr><th>Author</th><th>Title</th></tr>
<tr>
<td>{$i.author}</td>
<td class="title">{$i.title}</td>
</tr>
</tbody>
</table>
Note that the {foreach}{/foreach} tags have been moved to just before the <table>. This also produces the outputs exactly the way I want them, but I do not understand how this can be. Obviously, I am missing something fundamental here and would greatly appreciate some guidance.

Re: Smarty {foreach} being relocated in template

Posted: Mon Mar 04, 2013 6:19 pm
by Dr.CSS
That type of smarty code does not belong in a content box...