Schließen Sie Twig mit mehreren Parametern ein
Gibt es eine Möglichkeit, eine Twig-Vorlage mit mehr als einem Parameter einzuschließen?
Ich habe es versucht, aber es hat nicht funktioniert:
Der folgende Zweig wird von meinem Symfony-Controller gerendert:
{% 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 %}
Der Controller übergibt auch einige Parameter (dies sind nur einige Dummy-Daten):
$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"));
Dies ist eine Twig-Vorlage, die enthalten sein sollte:
<div>{{ picture }}</div>
<div><a href="{{ link }}"> <h3>{{ name }}</h3></a><br />{{ info }}<br /></div>