我试过这个,但它不起作用:
我的Symfony控制器呈现以下Twig:
{% 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 %}
Run Code Online (Sandbox Code Playgroud)
Controller还传递了一些参数(这只是一些Dummy-Data):
$objects['ob1']['type'] = "simple";
$objects['ob1']['picture'] = "this is …Run Code Online (Sandbox Code Playgroud)