我正在使用来自https://github.com/XaminProject/handlebars.php的 Handlebars PHP实现
在我使用嵌套的 Handlebars 模板中if/else,请参见下面的模板:
 <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>
在PHP 5.4安装中可以正常工作,但在PHP 5.2安装中会引发以下错误:
<b>Parse error</b>: syntax error, unexpected T_FUNCTION in <b>/.../Handlebars/Helpers.php</b> on line <b>71</b><br />
冲突的代码似乎是:
$this->add(
        'if', 
        function ($template, $context, $args, $source) {
            $tmp = $context->get($args);
            $buffer = '';
            if ($tmp) {
                $template->setStopToken('else');
                $buffer = $template->render($context);
                $template->setStopToken(false);
                $template->discard($context);
            } else {
                $template->setStopToken('else');
                $template->discard($context);
                $template->setStopToken(false);
                $buffer = $template->render($context);
            }
            return $buffer;
        }
    );
我是一个完整的PHP菜鸟,我只是使用这个 Handelbars PHP 实现在多个不同的环境中拥有相同的模板。
你能帮我解决这个问题吗?
谢谢