Closed diosney closed 10 years ago
Hi! I finally come with a working helper solution, but I don't know if it follows your recommended codestyle and that you have the interest to include in the code (maybe not since Handlebars.js don't have it? :( )
Well, this is the code, can you check it if it follows your code standard?
/**
* Create handler for the 'equal' helper.
* Needed for compatibility with PHP 5.2 since it doesn't support anonymous functions.
*
* @param $template
* @param $context
* @param $args
* @param $source
*
* @return string
* @throws InvalidArgumentException
*/
public static function _helper_equal($template, $context, $args, $source) {
$tmp = explode(' ', $args);
$buffer = '';
if (count($tmp) < 2) {
throw new InvalidArgumentException('Handlebars Helper equal needs 2 parameters');
}
if ($context->get($tmp[0]) == $tmp[1]) {
echo($tmp[1]);
$buffer = $template->render($context);
}
return $buffer;
}
Thanks for submitting your helper but,
Hi! I finally come with a working helper solution, but I don't know if it follows your recommended codestyle and that you have the interest to include in the code (maybe not since Handlebars.js don't have it? :( )
Well, this is the code, can you check it if it follows your code standard?
/**
- Create handler for the 'equal' helper.
- Needed for compatibility with PHP 5.2 since it doesn't support anonymous functions. *
- @param $template
- @param $context
- @param $args
- @param $source *
- @return string
@throws InvalidArgumentException */ public static function _helper_equal($template, $context, $args, $source) { $tmp = explode(' ', $args); $buffer = '';
if (count($tmp) < 2) { throw new InvalidArgumentException('Handlebars Helper equal needs 2 parameters'); } if ($context->get($tmp[0]) == $tmp[1]) {
echo($tmp[1]); $buffer = $template->render($context);
} return $buffer; }
— Reply to this email directly or view it on GitHubhttps://github.com/XaminProject/handlebars.php/issues/18#issuecomment-23618278 .
Okey :) I expected some answer like that :)
Then I will put my helper outside Handlebars.PHP source code.
Thanks
Hi,
Currently the
if
helper doesn't support equality checks and I'm in needed of that.I implemented an equality check helper in JavaScript, as defined in:
And is used like this:
I'm trying to convert that helper into Handlebars.PHP, but I'm having a hard time.
Can you help me on this?
Thanks!