Nesting phpBB-style content blocks
<p>My application uses a stripped-down version of the <code>assign_block_vars</code> content blocks used by phpBB to control it's template. In my code, there is a problem with nesting more than two blocks, for example the code from:</p>

<p>nest.php:</p>

<pre><code>$template-&gt;assign_block_vars('first', array(
    'NAME'      =&gt;  1,
));
$template-&gt;assign_block_vars('first.second', array(
    'NAME'      =&gt;  2,
));
$template-&gt;assign_block_vars('first.second.third', array(
    'NAME'      =&gt;  3,
));
</code></pre>

<p>nest.html:</p>

<pre><code>&lt;!-- BEGIN first --&gt;
{first.NAME}
&lt;!-- BEGIN second --&gt;
{first.second.NAME}
&lt;!-- BEGIN third --&gt;
{first.second.third.NAME}
&lt;!-- END third --&gt;
&lt;!-- END second --&gt;
&lt;!-- END first --&gt;
</code></pre>

<p>This generates <code>12</code>, rather than <code>123</code>. My <code>template</code> class contains the <code>assign_block_vars</code> function, I have stripped it down a little for readability and will try to explain ambiguities but please let me know if anything is unclear:</p>

<pre><code>function assign_block_vars($block_name, $vars)
{
    if (strstr($block_name, '.'))
    {
        //Nested Block
        $after_name = substr(strrchr($block_name, '.'), 1);
        $before_name = str_replace(".$after_name", '', $block_name);

        for($i = 0; $i &lt; count($this-&gt;iterations[$before_name]); $i++)
        {
            $this-&gt;data[$before_name][0][$after_name][$i][] = $vars;
        }
    }
    else
    {
        //Non-nested Block
        $this-&gt;data[$block_name][] = $vars;
    }
}
</code></pre>

<p>The <code>data</code> function is just building an array with all the compiled bits to put into the template. My compiled template doesn't seem to recognise that <code>third</code> is nested in <code>first.second</code>.  This is probably not enough information to debug with so I have put the full template class <a href="http://pastebin.com/5RsMpz5z" rel="nofollow">here</a>. I would really appreciate if someone could help with this, I have no idea how to fix it!</p>
