symfony - 如何显示 Victoire 文章的标签?

标签 symfony twig victoire

我想显示与 Blog 中的文章关联的标签Victoire 管理.

我该怎么做?

最佳答案

这可以通过使用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/

相关文章:

php - Symfony:组织多客户端应用程序的业务逻辑

javascript - 使用 twig 函数将带有 markdown 的 html 代码插入到 div 中

symfony - 奏鸣曲管理员 : Forgotten Password

php - symfony 子查询中出现错误

php - Symfony2 错误的实例通过 Twig 扩展传递

Symfony2 Assetic + Twig 模板 JavaScript 继承

symfony - Twig - 动态替换 GET 参数值