XaminProject / handlebars.php

Handlebars processor for php
331 stars 134 forks source link

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

Closed diosney closed 10 years ago

diosney commented 10 years ago

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 commented 10 years ago

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 ( https://github.com/XaminProject/handlebars.php/blob/8eb732f407121392015b1bcf032f8e4287fb3969/src/Handlebars/Helpers.php#L67 ) 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 commented 10 years ago

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 commented 10 years ago

thanks @diosney.