简体   繁体   中英

Create helper for render handlebars using php

I have a big problem and I don't understand how to solve this. So I have a class for helper :

class IfCondHelper implements HelperInterface
{
public function execute(Template $template, HandlebarsContent $context, $args, $source)
{
    $parsed_args = $template->parseArguments($args);

    if (count($parsed_args) != 3) {
        throw new \InvalidArgumentException(
            '"IfCond" helper expects exactly three arguments.'
        );
    }

    switch ($context->get($parsed_args[1])) {
        case "==":
            return ($context->get($parsed_args[0]) == $context->get($parsed_args[2])) ? $source : false;
            break;
..............
     }
}

Now in my template I do :

{{#ifCond 2 '==' 2}} {{data.oUser.number}} {{/ifCond}}

The problem is that the template doesn't show the value of data.oUser.number whitch is 4 but show the code data.oUser.number whitout interprete them. The helper works fine, because if I do :

{{#ifCond 2 '==' 2}} <p>Test</p> {{/ifCond}} 

This works fine. Can you help me please ? Thx in advance and sorry for my english

我发现了错误,需要在调用帮助程序后进行供应商渲染

return ($context->get($parsed_args[0]) == $context->get($parsed_args[2])) ? $template->render($context) : false;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM