1

We have a view, custom_view, that was created to be displayed on a page that is of the basic page content type. The basic page content type is using the Default View mode and has a taxonomy term, custom_tag.

Initially we thought about adding the block to the theme block layout, but that does not provide what we need. The custom_view should only be visible on the basic page content type for the Default View and not others.

How do you add Views to a View Mode?

The view has a contextual filter so it takes in the current language and it takes in the value of the custom_tag since it is present on the basic page content type.

  • @VishalPatil i had originally thought about adding the view as a reference field and defaulting the value so it will only display if it is in the view mode, but thought that adding a field for this was overkill. Do you think a field is overkill or would you recommend i reference the view in the template files and use preprocess hooks to get the view? – usernameabc Dec 12 '17 at 18:16
0

How do you add Views to a View Mode?

If you want to add a view to a content type's view mode there is many ways to do this depending on your exact requirement one might be the best fit

views field formatter

Use https://www.drupal.org/project/views_field_formatter will allow you to choose a formatter for a field and it will pass automatically the value of the field to the view

viewfield

https://www.drupal.org/project/viewfield will allow you to add a field and to choose what views can be choose and allows you to also include an argument on the node edit form

EVA: Entity Views Attachment

https://www.drupal.org/project/eva will allow you to create a specific EVA views display and configure it to appear for specific bundles (content types). After saving the view it will appear as a field in the display mode of that content types so it can be positioned appropriatelly

All the above module can take advantage of arguments and contextual filters so you can do very complex things with them

|improve this answer|||||
  • I ended up using the viewfield because it has the most configurations so i could select what View is selected per content type and fields along with easy to use Twig templates. – usernameabc Dec 27 '17 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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