Skip to main content

Getting a themed views title within a style tpl file

I ran into an issue today where I needed to get a themed views title from within a views row style template file (tpl). I tried using drupal_get_title() and menu_get_item() but the title elements were all blank for these. Next I inspected the $views object looking for the themed title but it was not listed. Finally, I discovered within $views->build_info the title and substitutions variables.

    [ title ] => My Views Title - %1
    [ substitutions ] => Array
            [ %1 ] => My Views Substitution
            [ !1 ] => My Views Argument from the URL

After that, getting the themed title was easy using the t() function.

  1. $title = t($view->build_info['title'], $view->build_info['substitutions']);