XaminProject / handlebars.php

Handlebars processor for php
331 stars 134 forks source link

"if/else" block helper does not work with loops #3

Closed joshpangell closed 11 years ago

joshpangell commented 11 years ago

Related to issue #2, loops do not work in conditionals.

The first proposed fix for the if else issue in commit 600215d actually does work, however the most recent fix in commit b9b6383 does not.

Example:

$h = new Handlebars_Engine;

echo $h->render(
        '<div class="entry">
          {{#if author}}
            {{#author}}<h1>{{firstName}} {{lastName}}</h1>{{/author}}
          {{else}}
            <h1>Unknown Author</h1>
          {{/if}}
        </div>
        ', 
        array(
            'author' => array(
                array(
                    'firstName' => "Nikola", 
                    'lastName' => "Tesla"
                ),
                array(
                    'firstName' => "Carl", 
                    'lastName' => "Segan"
                ),
                array(
                    'firstName' => "Neil", 
                    'lastName' => "Degrasse Tyson"
                )
            )

        )
    ); 

The latest commit, b9b6383, will render incorrectly

<div class="entry">
    <h1>Nikola Tesla</h1>
</div>

Commit 600215d will render correctly

<div class="entry">
    <h1>Nikola Tesla</h1>
    <h1>Carl Segan</h1>
    <h1>Neil Degrasse Tyson</h1>
</div>
everplays commented 11 years ago

thanks for the report @joshpangell.