【问题标题】:Drupal 8 article twig template - inserting filed valueDrupal 8 文章树枝模板 - 插入字段值
【发布时间】:2018-07-31 21:20:18
【问题描述】:

我正在尝试将字段值(全部从下拉列表中选择,机器名称 - field_categories)插入到树枝文章模板中,

{% if display_submitted %}
    <footer class="node__meta">
      {{ author_picture }}
      <div{{ author_attributes.addClass('node__submitted') }}>
        {% trans %}<i class="fa fa-calendar"></i>  {{ createdDate }} / <i class="fa fa-user"></i>  {{ author_name }} / <i class="fa fa-bars" aria-hidden="true"></i> {{ categories }}{% endtrans %}
        {{ metadata }}
      </div>
    </footer>
{% endif %}

【问题讨论】:

  • 您要在哪个模板中做事?在你自己的node--article--full.html.twig 中?

标签: templates twig drupal-8


【解决方案1】:

删除 {%trans%} 标记后,我能够使用该变量仅显示第一个值,但是如何从下拉列表中显示多个选定的值?

{% set categories = content.field_categories.0 %}
      
<i class="fa fa-calendar"></i>  {{ createdDate }} / <i class="fa fa-user"></i>  {{ author_name }} / <i class="fa fa-bars" aria-hidden="true"></i> {{ categories }} 
{{ metadata }}

【讨论】:

  • 你可以使用|first twig 过滤器,而不是使用.0。例如。 content.field_categories|first。它更优雅。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多