Score:0

How can I access row field values in the parent views template?

us flag

In views-view-fields--myview.html.twig I can print a views fully formatted/rewritten field with a variable like: {{ fields.field_my_view_field.content }}.

I am wondering if there is some way to print fields in the same fashion in the parent view template: views-view--myview.html.twig. This would require having access to these variables with the sub items (row) of the {{ rows }} variable.

Is this possible? And if so, what is the correct syntax to access?

leymannx avatar
ne flag
Have you tried to dump `{{ rows }}`? Is it an array that you can simply loop through?
Score:0
cn flag

You say that outputting the variables the template is supposed to be outputting is very powerful. Interesting, I would say this is the (only) correct way to use this template. In special cases it might be necessary to access field raw values, for example to add CSS classes to divs you put into the template, wrapping HTML markup around the content variables. The real purpose of this template.

======================================

If you want to control the rendering from the main View level then use a custom style plugin. Then you don't need to use the mentioned Views field templates. You can build a structure entirely from scratch rendering the fields as you want.

See Views style plugins.

leymannx avatar
ne flag
(I removed the noise from the question.)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.