Skip to main content
Category:

Question

How to get fields in views-view-unformatted.html.twig?

Solution

you can use this way to get any field in views-view-unformatted.html.twig :

{{ view.style_plugin.getField(KEY, 'FIELD_NAME') }}

Example

{#
/**
 * @file
 * Theme override to display a view of unformatted rows.
 *
 * Available variables:
 * - title: The title of this group of rows. May be empty.
 * - rows: A list of the view's row items.
 *   - attributes: The row's HTML attributes.
 *   - content: The row's content.
 * - view: The view object.
 * - default_row_class: A flag indicating whether default classes should be
 *   used on rows.
 *
 * @see template_preprocess_views_view_unformatted()
 */
#}
{% if title %}
    <h3>{{ title }}</h3>
{% endif %}
{% for key,row in rows %}
    {% set row_classes = [
        default_row_class ? 'views-row',
    ] %}
    <div{{ row.attributes.addClass(row_classes) }}>
        <div class="field_video">
            {{ view.style_plugin.getField(key, 'field_video') }}
        </div>
        <div class="field_date">
            {{ view.style_plugin.getField(key, 'field_date') }}
        </div>
        <div class="field_audio">
            {{ view.style_plugin.getField(key, 'field_audio') }}
        </div>
    </div>
{% endfor %}

Riadh Rahmi

Senior Web Developer PHP/Drupal & Laravel

I am a senior web developer, I have experience in planning and developing large scale dynamic web solutions especially in Drupal & Laravel.

Web Posts

Search

Page Facebook