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!

Related Questions

How to programmatically reference entities?

1  Asked on October 26, 2021 by sveggen


custom action plugin with ConfigurationForm

1  Asked on October 26, 2021


grouped paragraphs by field not filtering to current language

1  Asked on October 26, 2021 by turpentyne


How do I migrate node entity references?

0  Asked on October 26, 2021 by alexandre


Form textfield AJAX validation “deletes” injected services to form

1  Asked on October 26, 2021 by pedro-tentugal


Allowing anonymous users to contact node authors

1  Asked on October 26, 2021 by aroopk


How to cache a view for all users of a role?

1  Asked on October 26, 2021 by ktrev


Is it feasible to migrate by only migrating content?

2  Asked on October 26, 2021 by benjen


Get the breadcrumbs for a specific node other than the current

1  Asked on October 26, 2021 by nils-riedemann


Views exposed filters without “Apply” button

3  Asked on October 26, 2021


Saving form data and running custom queries in mysql

1  Asked on October 26, 2021 by benn-moffat


Add additional fields to the postal address

1  Asked on October 26, 2021 by jay-haase


Ask a Question

Get help from others!

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