【问题标题】:Drupal 8 Twig Entity Reference Sub Fields TemplatingDrupal 8 Twig 实体参考子字段模板
【发布时间】:2019-10-08 17:56:12
【问题描述】:

我正在尝试显示多值实体引用的子字段。

试过了:

    {% for item in node.field_related_items %}
            {{ item.content['#node'].field_author.value }}
    {% endfor %}

还有:

    {% for item in content.field_related_items %}
            {{ item.field_author }}
    {% endfor %}

如果我执行以下操作:

    {% for item in node.field_related_items %}
            {% set img1 = item.entity.field_featured_image %}
            {{ img1 }}
            {% set label1 = item.entity.label %}
            {{ label1 }}
    {% endfor %}

标签有效,但图像无效...

同样的事情:

item.entity.field_featured_image.value

没有成功,

仍然不确定如何显示实体引用的子字段...

请帮忙!

【问题讨论】:

    标签: drupal twig drupal-8 templating


    【解决方案1】:

    图像、分类、链接和普通字段模板的答案:

        {% for item in node.field_related_items %}
            <div class="col-sm-12 col-md-4">
                <div class="img-wrap">{{ file_url(item.entity.field_featured_image.entity.uri.value) }} </div>
    
                {% set cat1 = item.entity.field_blog_category.entity.label %}
                <div class="cat-wrap">{{ cat1 }}</div>
    
                {% set label1 = item.entity.label %}
                <div class="title-wrap">{{ label1 }}</div>
    
                {% set aut1 = item.entity.field_author.value %}
                <div class="author-wrap">By <span>{{ aut1 }}</span> | 
    
                {% set date1 = item.entity.field_publish_date.value %}
                {{ date1 }}</div>
    
                <a href="{{ path('entity.node.canonical', {'node': item.entity.id}) }}">Link</a>
    
            </div>
        {% endfor %}
    

    【讨论】:

      猜你喜欢
      • 2020-04-14
      • 2018-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-31
      • 1970-01-01
      • 2019-09-19
      • 2012-04-02
      相关资源
      最近更新 更多