Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Draven_Caine on
In drupal 7 you could use "views_get_view('view-name', 'view-display-name') to render a view in the theme template.
Does anyone know the way in drupal 8 to render a view in the twig template?
(My case is very simple, 2 column user profile, right column is a view of viewed user content)
Comments
くコ:彡
Not sure if uou can embed a view direcly in twig, however you can set it up in preprocess and print a variable...
Then in your template, in this case node:
{{ view_comments_recent }}
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
This would work great. Where
This would work great. Where do I put preprocess? (Still learn with the twig template system )
:)
In a file named ThemeName.theme, which needs to be in the root of your theme.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
I am running custom theme I
I am running custom theme I built so everything makes sense except how to hook the user profile vs the node.
View name: content
View display name: user_vehicle_embed
Thanks to Jeff Burnz I have this working.
This is to embed a view on the user profile.
In your .theme file add
Now go to your user.html.twig and call your variable with
{{ variable-name }}
Thanks again Jeff.
or use Twig Tweak
You can use Twig Tweak to get access to Views output - the Twig Tweak documentation shows simple syntax:
{{ drupal_view('who_s_new', 'block_1') }}
or more complex syntax:
I hope that's helpful!
Kristi
˚ ˚ ˚ ˚ ˚
Kristi Wachter
Drupal consultant, evangelist, and enthusiast