Hi,
I use your wonderful module, but I have a question :
I thought to create tpl.php file for field that I must format (everything in cap, delete caracters...)
But it's seems that when you export, it doesn't take care of the tpl...
How can i do that ?
Cheers,

Comments

mdlopresti’s picture

I was having a similar issue that I just got thru. Maybe I can help,

What format are you using? and What's your use case?

If you don't mind me asking.

soulston’s picture

I'm trying to remove £ symbols as they are not required in the data but overriding the tpl files seems to have no effect on any figures.

steven jones’s picture

Status: Active » Postponed (maintainer needs more info)

Which template files specifically aren't working?

grimreaper’s picture

Issue summary: View changes

Hello,

If your export is for a view in the BO, when clicking the link to download, it's your BO theme that will be used. So if your template is overriding the default one is in your front theme, it will not be used.

So to be sure your template will be used. You can implement an hook_theme_registry_alter to force the use of your template, that can be anywhere, in a custom module by example.

andrewmacpherson’s picture

The original post isn't clear whether it's about customizing the output using PHP generally, or using template files specifically.

It's possible to use Views API hooks to modify the output. Here's an example of hook_views_pre_render() which worked for me in a custom module. My use case was to prepare a CSV export summarising all node content, for auditing purposes as part of a content strategy review. I wanted to add a word-count, so I set the view up to include the node body field, and replaced it with a word-count like so...

/**
 * Implements hook_views_pre_render().
 *
 * Calculates a word-count from field_body content.
 */
function mymodule_views_pre_render(&$view) {
  if ($view->name == 'audit_content') {
    foreach ($view->result as $key => $row) {
      $text = $row->field_body[0]['raw']['value'];

      $text = html_entity_decode($text);
      $text = strip_tags($text);
      $word_count = str_word_count($text);

      // Handlers have already had their turn at pre_render(),
      // so we target the rendered markup.
      $view->result[$key]->field_body[0]['rendered']['#markup'] = $word_count;
    }
  }
}

hook_views_pre_render() would also be an appropriate way to tackle the use-case soulston mentioned, about removing £-signs.

turbogeek’s picture

Thanks @andrewmacpherson, I was implementing a hook_views_post_execute() and my exported data alterations were ignored. I guess that hook is called too soon. Implementing hook_views_pre_render(), which is called later, worked - thanks again :)

jkingsnorth’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

Sounds like this issue was fixed. Please do open a new support request if required.

jedihe’s picture

Using hook_views_pre_render as explained in #5 worked for me too. Thx @andrewmacpherson!

Caveat: I had to clear all caches for Views to notice the pre_render hook.