最佳答案
这可以通过使用render widget来实现.
创建 render_tags.html.twig 文件:
{# Resources/views/Article/render_tags.html.twig #}
{% if tags is not empty %}
<ul>
{% for tag in tags %}
<li>{{ tag }}</li>
{% endfor %}
</ul>
{% endif %}
在 Controller 中创建渲染方法:
/**
* @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,
];
}
添加小部件并配置它:
在选项卡中文章> 当前实体:
- 路线:
app_render_article_tags
- 参数:
{"id":"{{entity.id}}"}
关于symfony - 如何显示 Victoire 文章的标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43185543/