0

How to print fields value in views-view.html.twig I have created a views-view.html.twig file for my view slider_3. The template name is 'views-view--slider_3.html.twig' The view formatting is done by this template, but I need a field is come at begging position of the view:

<div class="slider-3-main">{{ rows.required_field }} <div{{ attributes.addClass(classes) }}> {{ title_prefix }} {% if title %} {{ title }} {% endif %} {{ title_suffix }}

How can be the field will written to display at {{ rows.required_field }}

1
  • I have created a ECK (drupal.org/project/eck) field in content type field as "Entity reference". Now need to print this field in a view. How can achieve it?
    – user50292
    Commented Sep 22, 2017 at 12:44

1 Answer 1

2

To get a field value of the first result row view.result[0] use the method EntityField::getValue of the view field:

{{ view.field.field_example.getvalue(view.result[0]) }} 
2
  • Waw this is amazing, its working. Thanks a lot for this. Could you please explain by which manner you have got this solution using EntityField::getValue
    – user50292
    Commented Aug 3, 2017 at 10:31
  • From the php code, see drupal.stackexchange.com/a/219537/47547
    – 4uk4
    Commented Aug 3, 2017 at 11:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.