我使用的是從https://github.com/XaminProject/handlebars.php把手PHP實現和嵌套的if/else發出
車把PHP實現在車把模板我使用嵌套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實現有跨幾個VARIOS環境相同的模板。
你能幫我解決這個問題嗎?
感謝
該庫與PHP 5.2不兼容,就這麼簡單。它與嵌套的任何東西無關。它使用匿名函數,因此至少需要PHP 5.3。 – deceze
爲什麼近距離投票?是一個** SO **有效的問題,可以用於其他用戶! – diosney
@deceze:我知道會很痛苦,但你能幫我把這些功能轉換成** 5.2 **有效嗎?我會嘗試在此之前聲明函數,並在此期間傳遞它,而不是匿名函數,但正如我所說的,我的PHP知識很少。 – diosney