而不是这样渲染我的TWIG中的每个幻灯片(见第6行):
{# loop out the slides #} {% for c in contents %} {% set i=i+1 %} {# increase slide number #} <div id="slide{{ i }}" class="slide" style="z-index:{{ i }};"> {# the slide itself,rendered by it's own template #} {% include 'BizTVArchiveBundle:ContentTemplate:'~c.template~'/view.html.twig' with {'contents': c,'ordernumber': i} %} </div> {% endfor %}
相反,我想把所有这些逻辑都保留在控制器中,以便将视图提供给一系列准备好的幻灯片.我该如何做这样的事情(见第9行):
//do stuff... foreach ($container->getContent() as $c) { $content[$i]['title'] = $c->getTitle(); $content[$i]['sort'] = $c->getSortOrder(); $content[$i]['data'] = $c->getData(); $content[$i]['template'] = $c->getTemplate()->getId(); $content[$i]['duration'] = $this->extract_seconds($c); $content[$i]['html'] = $this->render('BizTVArchiveBundle:ContentTemplate:'.$content[$i]['template'].'/view.html.twig',array( 'contents'=> $content[$i],'ordernumber' => 99,)); }
所有它现在给我($content [$i] [‘html]]的内容)
{"headers":{}}
如果您使用
include the template in the template更好,这样您就可以在视图层和控制器层中保留模板渲染.
但是,如果你真的想要它…
您可以使用2个服务来实现:twig使用Twig_Environment或templating.engine.twig,它是Symfony2 for Twig中的模板层,这可以轻松地切换为templateating.engine.php.
如果您使用twig服务,您可以看到the twig docs如何使用它:
$template = $this->get('twig')->render('/full/path/to/Resources/views/'.$content[$i]['template'].'/view.html.twig',array(...));
如果您使用templatesating.engine.twig服务,请参阅the templating docs如何使用它,这与Twig_Environment几乎完全相同.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。