I have a field loading hidden in an attachment view and I need to hook into that attachment to alter the output of the field.

It involves PHP and I'd rather hook into template.php rather than download some PHP module to store PHP code in my database.

I've tried hooking into theme_views_pre_render but I can't find my attachment, I can only modify the $view->attachment_before output.

That, plus I can't actually obtain the field values in this hook?

So how can I hook into a field value in an attachment?

1 Answer 1


An attachment is just like any other view (except that it is attached to other views), and so can be manipulated as such:

In template.php:

function THEMENAME_preprocess_views_view_fields(&$vars) {
  if (isset($vars['view']->name) && $vars['view']->name == 'VIEW_NAME' && $vars['view']->current_display == 'ATTACHMENT_NAME') {
    foreach ($vars['fields'] as $id => $field) {
      if ($id == 'FIELD_NAME') {
        $vars['fields'][$id]->content = 'new value';

Remember to clear your cache.

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.