* @author Behrooz Shabani * @author Dmitriy Simushev * @author Jeff Turcotte * @copyright 2014 Authors * @license MIT * @version GIT: $Id$ * @link http://xamin.ir */ namespace Handlebars\Helper; use Handlebars\Context; use Handlebars\Helper; use Handlebars\Template; /** * Handlebars halper interface * * @category Xamin * @package Handlebars * @author fzerorubigd * @author Behrooz Shabani * @author Dmitriy Simushev * @author Jeff Turcotte * @copyright 2014 Authors * @license MIT * @version Release: @package_version@ * @link http://xamin.ir */ class IfHelper implements Helper { /** * Execute the helper * * @param \Handlebars\Template $template The template instance * @param \Handlebars\Context $context The current context * @param \Handlebars\Arguments $args The arguments passed the the helper * @param string $source The source * * @return mixed */ public function execute(Template $template, Context $context, $args, $source) { $parsedArgs = $template->parseArguments($args); $tmp = $context->get($parsedArgs[0]); $context->push($context->last()); 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); } $context->pop(); return $buffer; } }