你知道PHP的任何流行的PHP模板引擎有当前上下文节点的概念吗?

This question is related to this one 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

As far as I know the only fairly popular open source template engine with this feature is Dwoo

PHP itself?

If I understand correctly you want this functionality

<?php foreach($catalog as $cd): ?>
    <tr>
        <td><?php echo $cd['title'] ?>
        <td><?php echo $cd['artist'] ?>
    </tr>
<?php endforeach ?>

You can have this on its own inside a template file and have your controller create the $catalog array and pass it to the template.

Is this not just like a normal foreach loop? So for example in Smarty the equivalent would be:

{foreach from=$cds item=cd}
    <tr>
        <td>{$cd->title}</td>
        <td>{$cd->artist}</td>
    </tr>
{/foreach}

but all the templating options, and PHP itself, can do this.

IMHO it is more confusing to omit the "invented" name, as there is no reference to what scope the data is coming from. It's much like the terribly abused extract() function in PHP that extracts an array to the current symbol table, which makes for very hard to manage code.