I'm trying to activate tokens in title and header.

For title I've done something like:

/**
 * Implementation of hook_views_pre_execute()
 */
function hook_views_pre_execute(&$view) {
      $title = &$view->display['default']->handler->view->display['page_2']->display_options['title']; // get reference
        if (strpos($title, ']') !== FALSE
            && $title = token_replace_multiple($title, array('user' => $user))) {
          drupal_set_title($title);
        }
}

And it's working.

But when I'm trying to change header, it doesn't work.

/**
 * Implementation of hook_views_pre_execute()
 */

      global $user;
      foreach ($view->display['default']->handler->view->display as $display => &$view_data) {
        $header = &$view_data->display_options['header']; // get reference
        if (strpos($header, ']') !== FALSE
            && $header = token_replace_multiple($header, array('user' => $user))) {
        }
      }

Why changes of header variable in $view variable using pre_execute are not applied into rendered view?

Comments

kenorb’s picture

Status: Active » Fixed

Ok, I've done it through preprocess_views_view:

/**
 * Implementation of hook_preprocess_views_view().
 */
function theme_preprocess_views_view(&$vars) {
  $header = &$vars['header']; // get reference
  if (strpos($header, ']') !== FALSE) {
    global $user;
    $header = token_replace_multiple($header, array('user' => $user));
  }
}
merlinofchaos’s picture

Note that there is a patch that adds token support to Views. Having tokens in the title and text areas could be valuable.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

mattgilbert’s picture

Where's the patch?

stinky’s picture

Subscribe

kenorb’s picture

Category: support » feature
Status: Closed (fixed) » Closed (duplicate)
ergophobe’s picture

Patch mentioned in #2 is probably this one:
#811480: Additional tokens for views
But so far, still failing testing. I couldn't find any others.

See also
http://drupal.org/node/462654