Views field template is ignored in CSV export

Created on 12 March 2023, almost 2 years ago
Updated 18 May 2024, 7 months ago

Views field template is ignored on CSV export.

I use twig file for custom text field with proper naming: views-view-field--view-name--nothing-6.html.twig.

It is picked up by views page display as expected, and produces markup altered by template. But CSV export gets standard output from views field, template with altered twig markup is ignored it seems.

Not sure if is it just me, can't figure out what is going on...

🐛 Bug report
Status

Active

Version

1.2

Component

Code

Created by

🇭🇺Hungary betarobot

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

Comments & Activities

  • Issue created by @betarobot
  • 🇨🇦Canada lindsay.wils

    Also seeing this issue, but I am not even seeing the templated output on the views display preview. Should this work? Thanks

  • 🇨🇦Canada lindsay.wils

    Is it possible to get an answer here? Should normal view field templates work here just like any other view? I am not seeing that, and I just want to be sure Im not doing anything wrong, so I dont waste anymore time, but no matter what I do, I cannot get theme template files here to do anything.

    Thanks

  • This seems to be related to this issue Views hooks not executed Fixed .
    The data export display is not being rendered and therefore some hooks are not executed. The views data export module includes a hook for this: hook_views_data_export_row_alter
    Here is an example:

    function my_module_views_data_export_row_alter(&$row, \Drupal\views\ResultRow $result, \Drupal\views\ViewExecutable $view) {
      if ($view->id() == 'my_view') {
        $node = $result->_entity;  // Get the node object
        $data = getData($node);
    
        foreach ($row as $key => &$value) {
          if (str_contains($key, 'nothing')) {
            $value = setCustomValue($data, $key);
          }
        }
      }
    }
    
  • 🇨🇦Canada lindsay.wils

    Thanks so much for the comment d_lav, this enabled mt to solved my issue and make my setup waaayyyyy more efficient, really appreciate that! :)

Production build 0.71.5 2024