【问题标题】:How do I show the Drupal Media library file media tag in a paragraph template?如何在段落模板中显示 Drupal 媒体库文件媒体标签?
【发布时间】:2021-08-21 18:23:40
【问题描述】:

当您在 Drupal 中安装了媒体库后,您就可以标记您的媒体,以便对图像和其他媒体进行排序。此标记字段是对分类术语的引用。我想知道是否可以在段落模板中显示此分类术语。

【问题讨论】:

    标签: drupal twig taxonomy templating media-library


    【解决方案1】:

    您可以使用 Twig 调整模块来做到这一点!

    首先你得到媒体目标的目标ID:

    {% set tid = content.field_img["#items"].entity.get("field_media_tags").0.target_id %}
    

    接下来,您可以像这样获取分类术语路径(首先检查是否存在实际的数字分类 id,否则返回空字符串):

    {% set taxonomy_term_path = (tid matches '/^\\d+$/' ? (path('entity.taxonomy_term.canonical', {'taxonomy_term': tid})) : "") %}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多