0
votes

new to drupal. I have created a view called "my_view_2". Inside my twig templates I use {{ my_view_2}} to render that view but nothing appears on the page.

If I declare the display of the view as page and assign a node to the view, then the view is rendered. But this way the node template is lost.

The above happens only to some views not very view I have and I can not find the differences between those that working and those that does not working.

any help is appreciated.

1
Is the variable my_view_2 defined?DarkBee
Yes it is defined as view at the administration area of drupal if I uderstand your question.Christoforos
Did you try to do {{ dump(my_view_2) }} in the template? (enable twig debug in drupal)DarkBee
It shows nothing @DarkBeeChristoforos

1 Answers

0
votes

Looks like you want to create a view with some kind of display then use twig template to style it. If that's the case, then decide which twig template you want override and copy it over to your /theme folder.

  1. Locate the template you wish to override.
  2. Copy the template file from its base location into your theme folder.
  3. (optionally) Rename the template according to the naming conventions in order to target a more specific subset of areas where the template is used.
  4. Modify the template as you want. With respect to views look at the below location for which template to copy/override : core/themes/stable/templates/views/views-view.html.twig).

For example, if we want to override "views-view.html.twig" template for our view, the following template names are valid:

views-view--[viewid]--[view-display-id].html.twig
views-view--[viewid]--page.html.twig
views-view--block.html.twig
views-view--[viewid].html.twig
views-view.html.twig

Once you copy a template file into your theme and clear the cache, Drupal will start using your instance of the template file instead of the base version.

Reference: Documentation: https://www.drupal.org/docs/8/theming/twig/twig-template-naming-conventions https://www.drupal.org/docs/8/theming/twig/working-with-twig-templates