1

I've been trying to modify a multiple-values field in a view. I thought I'd found the answer, creating a custom .tpl.php file using the naming structures detailed in Views UI's "Theme information" popup.

However, it seems that these tpl.php files are only respected when the field is output immediately, and not when it's set to be excluded from the display and then rewritten into another field using a replacement pattern. Views is seeing the file, and uses it if I don't have "exclude" ticked, but if I use a re-write pattern for the field, Views completely ignores the tpl.php file.

This happens regardless of whether "Use field template" is ticked for this field in Views UI's field Style Settings.

I almost always aggregate my fields like this to control the HTML output. How can I make Views respect my tpl.php file when re-writing the field content into another field?

0

1 Answer 1

0

Have you tried using the other method? Using template.php. I don't have time to test this, so consider this as a possible answer.

Add the following code to the bottom of your template.php file (located in /sites/all/themes/yourtheme/ folder)

function themename_preprocess_views_view_fields($vars){

      if ($vars['view']->name == "view_name" && $vars['view']->current_display == "block_1"){
        $vars['fields']['field_name']->content = 'hello world';
      }
    }
  • replace themename with your theme name
  • replace view_name with your view name
  • replace block_1 with your machine name
  • replace field_name with your field name

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.