added support for "else" in in if helper. fixes #2

XXX: could it be fixed in better way?
This commit is contained in:
behrooz shabani (everplays) 2012-11-17 12:46:24 +03:30
parent d99f9a7830
commit 600215d648

View File

@ -70,10 +70,15 @@ class Handlebars_Helpers
'if', 'if',
function ($template, $context, $args, $source) { function ($template, $context, $args, $source) {
$tmp = $context->get($args); $tmp = $context->get($args);
$parts = explode('{{else}}', $source, 2);
$buffer = ''; $buffer = '';
if ($tmp) { if ($tmp) {
$buffer = $template->render($context); $buffer = $template->getEngine()->render($parts[0], $context);
} } else {
if (isset($parts[1])) {
$buffer = $template->getEngine()->render($parts[1], $context);
}
}
return $buffer; return $buffer;
} }
); );