简体   繁体   English

如何在模板中使用 drupal_view 显示/打印相同的内容两次或更多次?

[英]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。

{{ 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.此代码仅适用于第一个 position 和第二个 position 它不起作用。 What can be done so that the content shows up in both places?可以做些什么来让内容在两个地方都显示出来?

Got the solution from the Drupal community:从 Drupal 社区获得解决方案:

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:将渲染 output 分配给 twig 变量并打印该变量两次:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM