Note that there are some explanatory texts on larger screens.

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

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload