TransWikia.com

How to print the Views title in page.tpl.php?

Drupal Answers Asked by Szymon Panecki on February 10, 2021

I could print the view with this code in page.tpl.php.

print $view->display['view_display_name']->display_options['title'];

How can I print the Views title ?

3 Answers

Add the following code in your template.php

function themename_preprocess_page(&$variables) {
  $name = 'view_machine_name';
  $display_id = 'block_1';
  $view = views_get_view($name);
  if(isset($view) && !empty($view)) {
    $head_title = $view->get_title();
    $variables['view_title'] = $head_title;
  }
}

add the following variable anywhere in the page.tpl.php file used by your theme.

 print $view_title; 

Answered by JImmy on February 10, 2021

If I correctly understand your question, you are actually looking for how to define $view. That can easily be done with views_get_view(). Add <?php $view=views_get_view('YOUR-VIEW'); ?> to page.tpl.php or predefine the variable with template_preprocess_page() in your theme's template.php file. You can then print the View's title with your code line.

Answered by Jeroen on February 10, 2021

You can aptly use this function views_embed_view(). This will help you to print out the view, passing arguments.

Answered by Neo on February 10, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP