7

I'm using the latest version 8.2.4 of drupal core, which ships with view.

After enabling the internal cache system, some of my views get broken.

My view configuration is:

uuid: xxx langcode: de status: true dependencies: config: - block.block.unternavigation_unternehmen - core.entity_view_mode.node.standort - field.storage.node.field_ansprechpartner - node.type.standort - system.menu.main content: - 'block_content:formulare:13194389-5c27-4811-aa91-478cd4d80d52' module: - node - user id: standorte label: Standorte module: views description: '' tag: '' base_table: node_field_data base_field: nid core: 8.x display: default: display_plugin: default id: default display_title: Master position: 0 display_options: access: type: perm options: perm: 'access content' cache: type: tag options: { } query: type: views_query options: disable_sql_rewrite: false distinct: false replica: false query_comment: '' query_tags: { } exposed_form: type: basic options: submit_button: Anwenden reset_button: false reset_button_label: Zurücksetzen exposed_sorts_label: 'Sortieren nach' expose_sort_order: true sort_asc_label: Aufsteigend sort_desc_label: Absteigend pager: type: some options: items_per_page: 20 offset: 0 style: type: default options: row_class: '' default_row_class: true uses_fields: false row: type: 'entity:node' options: relationship: none view_mode: default fields: title: id: title table: node_field_data field: title entity_type: node entity_field: title label: '' alter: alter_text: false make_link: false absolute: false trim: false word_boundary: false ellipsis: false strip_tags: false html: false hide_empty: false empty_zero: false settings: link_to_entity: true plugin_id: field relationship: none group_type: group admin_label: '' exclude: false element_type: '' element_class: '' element_label_type: '' element_label_class: '' element_label_colon: true element_wrapper_type: '' element_wrapper_class: '' element_default_classes: true empty: '' hide_alter_empty: true click_sort_column: value type: string group_column: value group_columns: { } group_rows: true delta_limit: 0 delta_offset: 0 delta_reversed: false delta_first_last: false multi_type: separator separator: ', ' field_api_classes: false filters: status: value: '1' table: node_field_data field: status plugin_id: boolean entity_type: node entity_field: status id: status expose: operator: '' group: 1 type: id: type table: node_field_data field: type value: standort: standort entity_type: node entity_field: type plugin_id: bundle sorts: field_sortierung_value: id: field_sortierung_value table: node__field_sortierung field: field_sortierung_value relationship: none group_type: group admin_label: '' order: ASC exposed: false expose: label: '' plugin_id: standard title: '' header: { } footer: entity_block_content: id: entity_block_content table: views field: entity_block_content relationship: none group_type: group admin_label: '' empty: false tokenize: false target: 13194389-5c27-4811-aa91-478cd4d80d52 view_mode: default bypass_access: false plugin_id: entity empty: { } relationships: { } arguments: { } display_extenders: { } cache_metadata: max-age: -1 contexts: - 'languages:language_content' - 'languages:language_interface' - 'user.node_grants:view' - user.permissions tags: { } footer_block: display_plugin: block id: footer_block display_title: Footer position: 5 display_options: display_extenders: { } display_description: '' footer: { } defaults: footer: false filters: false filter_groups: false filters: status: value: '1' table: node_field_data field: status plugin_id: boolean entity_type: node entity_field: status id: status expose: operator: '' group: 1 type: id: type table: node_field_data field: type value: standort: standort entity_type: node entity_field: type plugin_id: bundle field_nicht_im_footer_value: id: field_nicht_im_footer_value table: node__field_nicht_im_footer field: field_nicht_im_footer_value relationship: none group_type: group admin_label: '' operator: '=' value: '0' group: 1 exposed: false expose: operator_id: '' label: '' description: '' use_operator: false operator: '' identifier: '' required: false remember: false multiple: false remember_roles: authenticated: authenticated is_grouped: false group_info: label: '' description: '' identifier: '' optional: true widget: select multiple: false remember: false default_group: All default_group_multiple: { } group_items: { } plugin_id: boolean filter_groups: operator: AND groups: 1: AND cache_metadata: max-age: -1 contexts: - 'languages:language_content' - 'languages:language_interface' - 'user.node_grants:view' - user.permissions tags: { } kontakt: display_plugin: page id: kontakt display_title: Kontakt position: 1 display_options: display_extenders: { } path: kontakt display_description: '' menu: type: normal title: Kontakt description: '' expanded: false parent: '' weight: -42 context: '0' menu_name: main cache_metadata: max-age: -1 contexts: - 'languages:language_content' - 'languages:language_interface' - 'user.node_grants:view' - user.permissions tags: { } standorte: display_plugin: page id: standorte display_title: Standorte position: 2 display_options: display_extenders: { } display_description: '' path: standorte footer: { } defaults: footer: false sorts: false menu: type: normal title: Standorte description: '' expanded: false parent: 'menu_link_content:a1b2d8c6-75af-459e-937e-0d1c792ef9b4' weight: -48 context: '0' menu_name: main sorts: created: id: created table: node_field_data field: created relationship: none group_type: group admin_label: '' order: ASC exposed: false expose: label: '' granularity: second entity_type: node entity_field: created plugin_id: date cache_metadata: max-age: -1 contexts: - 'languages:language_content' - 'languages:language_interface' - 'user.node_grants:view' - user.permissions tags: { } standorte_ansprechpartner: display_plugin: attachment id: standorte_ansprechpartner display_title: 'Standorte Ansprechpartner' position: 4 display_options: display_extenders: { } display_description: '' style: type: default options: row_class: '' default_row_class: true uses_fields: false defaults: style: false row: false fields: false footer: false row: type: 'entity:node' options: relationship: none view_mode: standort fields: field_ansprechpartner: id: field_ansprechpartner table: node__field_ansprechpartner field: field_ansprechpartner relationship: none group_type: group admin_label: '' label: '' exclude: false alter: alter_text: false text: '' make_link: false path: '' absolute: false external: false replace_spaces: false path_case: none trim_whitespace: false alt: '' rel: '' link_class: '' prefix: '' suffix: '' target: '' nl2br: false max_length: null word_boundary: false ellipsis: false more_link: false more_link_text: '' more_link_path: '' strip_tags: false trim: false preserve_tags: '' html: false element_type: '' element_class: '' element_label_type: '' element_label_class: '' element_label_colon: false element_wrapper_type: '' element_wrapper_class: '' element_default_classes: true empty: '' hide_empty: false empty_zero: false hide_alter_empty: true click_sort_column: target_id type: entity_reference_entity_view settings: view_mode: standort group_column: target_id group_columns: { } group_rows: true delta_limit: 0 delta_offset: 0 delta_reversed: false delta_first_last: false multi_type: separator separator: ', ' field_api_classes: false plugin_id: field attachment_position: after displays: standorte: standorte footer: { } cache_metadata: max-age: -1 contexts: - 'languages:language_content' - 'languages:language_interface' - 'user.node_grants:view' - user.permissions tags: - 'config:field.storage.node.field_ansprechpartner' standorte_kurzbeschreibung: display_plugin: attachment id: standorte_kurzbeschreibung display_title: 'Standorte Kurzbeschreibung' position: 3 display_options: display_extenders: { } display_description: '' displays: standorte: standorte footer: { } defaults: footer: false header: false header: entity_block: id: entity_block table: views field: entity_block relationship: none group_type: group admin_label: '' empty: false tokenize: true target: unternavigation_unternehmen view_mode: default bypass_access: true plugin_id: entity cache_metadata: max-age: -1 contexts: - 'languages:language_content' - 'languages:language_interface' - 'user.node_grants:view' - user.permissions tags: { } 

The main structure is:

View: - Attachement before (standorte_kurzbeschreibung) node--view--standorte--standorte-kurzbeschreibung.html.twig - Page (standorte) node--view--standorte--standorte.html.twig - Attachment after (standorte_ansprechpartner) node--view--standorte--standorte-ansprechpartner.html.twig 

When enabling cache, drupal uses same node template (both are set to display rendered node) for attachement before and page rows. The templates are using default suggestion hooks node--view--view-id--display-id.html.twig.

Also the configured block (footer_block) uses the same template when enabling cache.

Any suggestion how to solve this?

2 Answers 2

15

The answer is simple and possible a bit unfortunate for you.

Do not use node--view-* templates. They are broken.

See this core issue here. The problem is that fixing it would result in a performance regression for other sites that do not use that feature; as more cache variations have to be stored if the same node is displayed in multiple views.

Instead of that, use a unique view mode for your view that you can address as a template through that.

0

We ended up working around this issue by creating a new content "display" mode called "Topper" (like a Teaser, but call yours whatever you want).

This allowed us to create a Twig template for that new Display using the node--type--topper.html.twig hint, instead of the node--view--view-id--display-id.html.twig hints.

Then we set the specific View to use that Display for the output (instead of, say, the Teaser), instead of themeing the View.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.