/** * {@inheritdoc} */ public function execute(Template $template, Context $context, $args, $source) { // Check if there is at least one argument $parsed_arguments = $template->parseArguments($args); if (count($parsed_arguments) == 0) { throw new \InvalidArgumentException('"l10n" helper expects at least one argument.'); } $text = $context->get(array_shift($parsed_arguments)); // We need to escape extra arguments passed to the helper. Thus we need // to get escape function and its arguments from the template engine. $escape_func = $template->getEngine()->getEscape(); $escape_args = $template->getEngine()->getEscapeArgs(); // Check if there are any other arguments passed into helper and escape // them. $local_args = array(); foreach ($parsed_arguments as $parsed_argument) { // Get locale argument string and add it to escape function // arguments. array_unshift($escape_args, $context->get($parsed_argument)); // Escape locale argument's value $local_args[] = call_user_func_array($escape_func, array_values($escape_args)); // Remove locale argument's value from escape function argument array_shift($escape_args); } $result = getlocal($text, $local_args); return new SafeString($result); }
/** * {@inheritdoc} */ public function execute(Template $template, Context $context, $args, $source) { // Get name of the parent template $parsed_args = $template->parseArguments($args); if (count($parsed_args) != 1) { throw new \InvalidArgumentException('"extends" helper expects exactly one argument.'); } $parent_template = $context->get(array_shift($parsed_args)); // Render content inside "extends" block to override blocks $template->render($context); // We need another instance of \Handlebars\Template to render parent // template. It can be got from Handlebars engine, so get the engine. $handlebars = $template->getEngine(); // Render the parent template $this->level++; $buffer = $handlebars->render($parent_template, $context); $this->level--; if ($this->level == 0) { // The template and all its parents are rendered. Clean up the // storage. $this->blocksStorage->clear(); } return $buffer; }