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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀