twigdrupal-8drupal-views

How to show/print same content twice or more using drupal_view in a template?


I have a page where I need to show/print the same content twice. For this, I am using drupal_view.

{{ drupal_view('product_content', 'page_1', node.id) }}

This code works only for the first position and for the second position it doesn't work. What can be done so that the content shows up in both places?


Solution

  • Got the solution from the Drupal community:

    When something is rendered, the render system remembers what has been rendered and won't re-render that. Assign the render output to a twig variable and print the variable twice:

    > {% set product_content = drupal_view( ... )|render %}
    > {{ product_content }} 
    > {{ product_content }}