有没有一种方法,包括树枝模板与一个以上的参数?
我想这一点,但它没有工作:
下面的树枝被我的Symfony控制器呈现:
{% for object in objects %}
{% if object.type == "simple" %}
{% include 'BBLWebBundle:content:simple.html.twig'
with [{'picture': object.picture}, {'link': object.link}, {'name': object.name}, {'info': object.info}] %}
{% elseif object.type == "mp3" %}
{% include 'BBLWebBundle:content:mp3.html.twig'
with [{'picture': object.picture}, {'link': object.link}, {'name': object.name}, {'info': object.info}] %}
{% elseif object.type == "video" %}
{% include 'BBLWebBundle:content:video.html.twig'
with [{'picture': object.picture}, {'link': object.link}, {'name': object.name}, {'info': object.info}] %}
{% endif %}
{% endfor %}
控制器也通过一些参数(这只是一些占位数据):
$objects['ob1']['type'] = "simple";
$objects['ob1']['picture'] = "this is a picture";
$objects['ob1']['link'] = "#";
$objects['ob1']['info'] = "Oh wooow some Info";
$objects['ob1']['name'] = "Potato";
return $this->render('BBLWebBundle:Base:content.html.twig',
array('objects' => $objects, 'title' => "Im very cool Title"));
这是一个枝杈模板应该包括:
<div>{{ picture }}</div>
<div><a href="{{ link }}"> <h3>{{ name }}</h3></a><br />{{ info }}<br /></div>