2016-07-15 62 views
0

我有一个大问题,我不明白如何解决这个问题。 所以我有助手类:使用php创建渲染控制条的助手使用php

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; 
.............. 
    } 
} 

现在在我的模板,我做的:

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

的问题是,模板不显示的data.oUser.number值whitch是4,但显示了代码data.oUser.number没有解释它们。帮手工作正常,因为如果我这样做:

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

这工作正常。你能帮我吗 ? THX提前对不起我的英语

回答

0

我发现错误,需要做的呼叫后supplimentaire渲染帮手

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