dongsha9208 2014-07-18 12:39
浏览 51
已采纳

如何在自定义树枝函数中呈现内容?

I'm getting prices and bookings from different sources in one flat booking table like this:

record    2014-06-07   2014-06-14   2014-06-21   2014-06-28
1           2000.00     2500.00       2500.00      3000.00
           array(3)     array(null)   array(2)     array(1)

2           3000.00     3500.00       3500.00      2800.00
         array(null)    array(1)     array(null)  array(null)

Now I need to render the columns with prices and bookings into a nice layout. So I wrote a custom twig extension and gave them prices and bookings as arguments.

So my question is: How can I render the result of the custom Twig_Function within the twig extension? Sometimes I need to render only the price and sometimes I need to render the price and 3 bookings within a week.

Before using the twig extension I tried to render a custom controller. But that was very slow because having lots of rows and columns in the table.

  • 写回答

2条回答 默认 最新

  • dougekui1518 2014-07-24 12:27
    关注

    First it did not worked for me, because I was getting a circularReferenceException. I helped me with injection an existing Twig Enviroment. So my service definition looks like

    app.twig.extension:
      class: App\AppBundle\Twig\AppExtension
      arguments: ["@twig"]
      tags:
          - { name: twig.extension }
    

    An the constructor looks like this:

    function __construct(\Twig_Environment $environment)
    {
        $this->environment = $environment;
    }
    

    In the function then I use

    public function myFunction()
    {
        // logic...
    
        return $this->environment->display(extension, arguments)
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器