Newbie here!
I have created a view with some fields and i want to group some of the fields in one wrapper and remaining in another wrapper and also want to change the structure i.e. adding own wrappers and classes.
Thanks.
To add and then group fields in views, you can do the following (if not using a view mode/template).
Add all the fields you need, and mark each of them "Exclude from display".
Add another field of type 'Custom text'. DO NOT exclude this one.
Click on the 'Custom text' field to open its options.
Inside the textarea there, you can input custom html using the tokens from the fields above to populate it. You can find the values you'll need for replacement if you click on the "Replacement patterns" dropdown just below the textarea.
You don't need templates for grouping fields in views. If you have other question, please provide more details.
Example:
Add the fields Title and Changed, hide Title by checking "Exclude from display". Go in the last field of the group Changed, open REWRITE RESULTS, check "Override the output of this field with custom text" and put in the text box:
<div class="myclass">{{ title }} was changed at {{ changed }}</div>
This is the result:
Title was changed at 08/18/2016 - 13:50
If you want to use a twig template instead of rewriting the results in a view, you just need to:
views-view-fields--our_team--page_1.html.twig
, where our_team
is the machine name of the view and page_1
is the display machine name.{{ fields.field_staff_photo.content }}
but that will change depending on the names of your fields.Using the rewrite results option in a view is probably quicker and clearer to work with, but if you want to keep all your markup in files, that could be a good reason to go with a template.
If anyone is just looking to group results from a Drupal view by a field, here are answers from a similar thread. I often use the top answer there when I have categorical data to organize.