Disable theme_debug when rendering the view

Created on 27 July 2015, almost 10 years ago
Updated 11 June 2024, about 1 year ago

Hi,

Drupal 7.33 introduced a useful theme_debug config option to inspect template suggested and used:
https://www.drupal.org/drupal-7.33-release-notes

The effect of this option is that debug markup is inserted into Drupal output.

However when this option is enabled, Views Data Export does not prevent debug markup to be inserted in rendered results, breaking CSV and XML formats.

Here is an example of a rendered data export CSV display:

<!-- THEME DEBUG -->
<!-- CALL: theme('views_data_export') -->
<!-- BEGIN OUTPUT from 'sites/all/modules/views_data_export/theme/views-data-export.tpl.php' -->


<!-- THEME DEBUG -->
<!-- CALL: theme('views_data_export_csv_header') -->
<!-- BEGIN OUTPUT from 'sites/all/modules/views_data_export/theme/views-data-export-csv-header.tpl.php' -->
"Name","","Roles","Member for","Last access"

<!-- END OUTPUT from 'sites/all/modules/views_data_export/theme/views-data-export-csv-header.tpl.php' -->



<!-- THEME DEBUG -->
<!-- CALL: theme('views_data_export_csv_body') -->
<!-- BEGIN OUTPUT from 'sites/all/modules/views_data_export/theme/views-data-export-csv-body.tpl.php' -->
"User 1","user-1@example.com","","4 days 2 hours","4 days 1 hour ago"
"User 2","user-2@example.com","","4 days 4 hours","4 days 26 min ago"
"User 3","user-3@example.com","","4 days 8 hours","4 days 5 hours ago"
"User 4","user-4@example.com","premium","4 days 23 hours",""

The following patch disables this option before rendering the view.

🐛 Bug report
Status

Closed: works as designed

Version

3.0

Component

Code

Created by

🇫🇷France manu manu Aix-en-Provence

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • For the record, it is possible to disable the theme debug output by calling the Twig service right before your rendering.

    For instance :

          $node = \Drupal::entityTypeManager()->getStorage('node')->load(1);
          $build = \Drupal::entityTypeManager()->getViewBuilder('node')->view($node);
    
          // Make sure no debug output in XML.
          \Drupal::service('twig')->disableDebug();
    
          $output = \Drupal::service('renderer')->renderPlain($build);
    
Production build 0.71.5 2024