This question is related to this one http://stackoverflow.com/questions/3940927/is-there-anything-like-dwoo-s-with-or-loop-in-smarty-3-or-earlier
Basically I want to have something like current node from XSLT templates.
In XSLT when I write something like:
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
artist actually refers to catalog/cd[1]/artist (and of course [2],[3] ... and so on if there are more cd-s)
Current context in which field names are understood changes inside for-each block.
I very much like this functionality. Do you know any popular PHP template engine (other than Dwoo) that has this functionality?
UPDATE:
Tim Fountain suggested:
// smarty
{foreach from=$cds item=cd}
<tr>
<td>{$cd->title}</td>
<td>{$cd->artist}</td>
</tr>
{/foreach}
but I'd prefer something like:
// dwoo
{foreach from=$cds}
<tr>
<td>{$title}</td>
<td>{$artist}</td>
</tr>
{/foreach}
which will not work.
Think about nested loop (let's assume cd has multiple artists):
// smarty
{foreach from=$cds item=cd}
<tr>
<td>{$cd->title}</td>
<td><ul>
{foreach from=$cd->artist item=$ar}
<li>{$ar}</li>
{/foreach}
</ul></td>
</tr>
{/foreach}
when I'd prefer
// dwoo
{foreach from=$cds}
<tr>
<td>{$title}</td>
<td><ul>
{foreach from=$artist}
<li>{$}</li>
{/foreach}
</ul></td>
</tr>
{/foreach}
Also If I also have a collection of music on cassettes I can iterate over it with same code:
// dwoo
{foreach from=$mcs}
<tr>
<td>{$title}</td>
<td><ul>
{foreach from=$artist}
<li>{$}</li>
{/foreach}
</ul></td>
</tr>
{/foreach}
I don't know if I could use same name for loop variable over and over like here:
// smarty, buggy?
{foreach from=$mcs item=o}
<tr>
<td>{$o->title}</td>
<td><ul>
{foreach from=$o->artist item=o}
<li>{$o}</li>
{/foreach}
</ul></td>
<td>{$o->title}</td>
</tr>
{/foreach}
But I suppose inner $o would have overwritten outer $o