Score:2

Is there a way to not include the {{ content }} variable in a node template and still have the node cache clear when the node is updated?

ng flag

We have nodes that have dozens of fields and have elected to not include the {{ content }} variable as it is tedious and looks messy having something like the following just to not print the fields. We're manually outputting each field as needed like {{ content.myfield }}.

The problem is that when the {{ content }} variable is not in a template then that node's cache does not get cleared when a user modifies the node's content and they have to contact and admin to clear the Drupal caches.

Surely there must be a way to have a node's cache cleared when it is updated and its theme template does not have the {{ content }} variable. Please help.

{{ content|without('field_blog_posts','field_breadcumb_t','field_call_to_action','field_call_to_actions_title','field_customer_support_body','field_customer_support_button_te','field_customer_support_image','field_customer_support_title','field_hero_body','field_solutions_hero_image','field_hero_link_1','field_hero_link_2','field_hero_title','field_learn_more_text','field_meta_tags','field_newsletter_signup_banner','field_newsletter_signup_banner_m','field_product_spotlight_title','field_read_more_link_text','field_section_one_category_1','field_section_one_category_2','field_section_one_sub_title','field_section_one_title','field_section_one_video','field_section_two_category_1','field_section_two_category_2','field_section_two_sub_title','field_section_two_title','field_section_twovideo','field_section_two_view_all_link','field_spotlighted_product') }}
Score:6
in flag

Install the twig tweak module (v3.x) and then use cache_metadata filter.

When using raw values from entities or render arrays it is essential to ensure that cache metadata are bubbled up.

{# Ensure content cache metadata is rendered for the display as a whole. #}
{{ content|cache_metadata }}
Score:4
ru flag

You can simply render it into a variable and just do nothing with it:

{# rendering the content into a variable doesn't visibly render anything, but forces the cache to bubble up #}
{% set dummy = content|render %}
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.