Skip to content
This repository has been archived by the owner on Jan 26, 2019. It is now read-only.

Nested if/else helper not working on PHP 5.2 #16

Closed
diosney opened this issue Aug 21, 2013 · 3 comments · Fixed by #17
Closed

Nested if/else helper not working on PHP 5.2 #16

diosney opened this issue Aug 21, 2013 · 3 comments · Fixed by #17

Comments

@diosney
Copy link
Contributor

diosney commented Aug 21, 2013

I know PHP 5.2 is a bit old but is the version that some hosting providers (like HostGator) have installed so it cann't be left forgotten.

This code is working ok in PHP 5.4 but for some reason in a PHP 5.2 installation it throws the following error:

<b>Parse error</b>: syntax error, unexpected T_FUNCTION in <b>/.../Handlebars/Helpers.php</b> on line <b>71</b><br />

My Handlebars template is has follows:

     <div class="text-align-{{ options.alignment }} border-bottom-{{ options.style }}" style="border-width: {{ options.width }}px; border-color: {{ options.color }}">
        {{#if options.use_title_separator}}
            <div>
                {{#if options.back_to_top}}
                    <a href="" onclick="return false;">{{ options.text_label }}</a>
                {{else}}
                    {{ options.text_label }}
                {{/if}}
            </div>
        {{/if}}
    </div>

It could be great if you can help me on this.

Thanks

@everplays
Copy link
Contributor

I'm not sure if this is the only compatibility issue with php 5.2 because we wrote it with php 5.3+ in our minds. but I would be happy to see php 5.2 support, so patches are welcome.

anyways, this one can be fixed easily. just make helpers (

protected function addDefaultHelpers()
) static and register 'em like: $this->add('if, array('Handlebars_Helpers', '_if')).
for example if helper (defined in line 71), should be like:

public static function _f($template, $context, $args, $source) {
  // body is the same
}

@diosney
Copy link
Contributor Author

diosney commented Aug 21, 2013

Yeah!!!! Thanks!!!! It worked like a charm!!!

I will push this changes to make at least the helpers compatible with 5.2 :D

Until now I didn't found any other issues, if I found another one I will report it or try to fix it.

You rock!

@everplays
Copy link
Contributor

thanks @diosney.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants