How do I return a field value from Views when using a Views Relationship? Im using views-view-fields--pagedisplay--html.twig

fields.title.content

seems to return titles but

fields.field_movie_length.content

does not return any vales, however the field exists if I

{{ dsm(fields) }}

I have Twig Tweak & Twig Feld Value modules installed also.

up vote 0 down vote accepted

Views templates don't work like field templates, so the modules you have installed won't help. Though you can use node and field templates by switching the Format of the View to Content instead of Fields or you can configure a single field to use a field template in STYLE SETTINGS.

If you want to use the views templating system you might consider switching to the format Table, because this template has the most options.

The template you have now has very limited options. The field array is exactly the output you have configured in Views UI and this is the place where you should apply your adjustments.

After all of that, if you still want to see which fields and their content are delivered to your template, then use this loop for debugging:

views-view-fields.html.twig

{% for key, field in fields %}
  <p><i>{{ key }}:</i> {{ field.content }}</p>
{% endfor %}

field.content is finally rendered html, so you can't do much with it. The array keys contain the field names of the fields you have selected and arranged in the FIELDS section of the Views UI. It doesn't matter whether the fields come from relationsships.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.