1

I'm embedding a View inside my custom module, using views_embed_view

From the docs for this function:

Note that this function does NOT display the title of the view. If you want to do that, you will need to do what this function does manually, by loading the view, getting the preview and then getting $view->get_title().

However, my View has no title, instead I've set my contextual filter to override the title (from the arguments in the url). How do I get this title?

Thanks

Edit: Here is a screengrab of my contextual filter settings. I'm actually currently using the default taxonomy_term view that comes with Views out of the box. enter image description here

  • 1
    how is your contextual filter overriding the title? using that logic and drupal_set_title() should do it unless I am missing something here. – Jimajamma Sep 3 '12 at 17:01
  • May you show the code you are using for your contextual filter, or the settings you are using for that contextual filter? Without using custom code, a contextual filter doesn't change the page title. – kiamlaluno Sep 3 '12 at 19:39
  • Added screengrab of settings to original post. Thanks. – leon.nk Sep 4 '12 at 8:53
0

Okay I got it...

After executing the view in your code (e.g. with a $view->preview()). You need to find the argument in the view that sets the title, and then call set_title() on it.

Here's what I did (note that I'm assuming that in the case of multiple arguments setting titles it's the last one that works, hence the array_reverse, haven't tested this yet).

<?php
$view = views_get_view('taxonomy_term');
$view->preview('panel_pane_1', array($tid));
foreach (array_reverse($view->argument) as $argument) {
    if ($argument->options['title_enable']) {
        $page_title = $argument->get_title();
        break;
    }
}
?>

Hope that helps someone else out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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