答案 0 :(得分:2)
可以使用render widget。
{# Resources/views/Article/render_tags.html.twig #}
{% if tags is not empty %}
<ul>
{% for tag in tags %}
<li>{{ tag }}</li>
{% endfor %}
</ul>
{% endif %}
/**
* @Route("/renderArticleTags/{id}", name="app_render_article_tags")
* @Template("Article/render_tags.html.twig")
*/
public function renderArticleTagsAction(Article $article)
{
$tags = [];
/** @var \Victoire\Bundle\BlogBundle\Entity\Tag $tag */
foreach ($article->getTags() as $tag) {
$tags[] = $tag->getTitle();
}
return [
'tags' => $tags,
];
}
在标签文章&gt; 当前实体:
app_render_article_tags
{"id":"{{entity.id}}"}