custom page.tpl.php for a drupal view


Solution 1

You can create a template file to theme almost any aspect of views output. In your case you want to create a custom template for your page display.

On the view designer, click the Theme link in Basic Settings. You'll see some template file naming options depending on if you want to theme the whole view (e.g., views-view--example--page.tpl.php), each row (e.g., views-view-fields--example--page.tpl.php) and so on.

Copy the appropriate template you want to customize from /sites/all/modules/views/theme to your theme and customize as you wish.

Once you create your custom template file, you can go back to the view designer Theme link to make sure it is being used. Your template should be bolded.

Hope this helps.

Solution 2

Per Allartk's solution
In Drupal 7 template.php:

function <theme>_preprocess_page(&$variables) {
    if (($views_page = views_get_page_view()) && $views_page->name === "galleries") {
      $variables['theme_hook_suggestions'][] = 'page__views__galleries';

Then in your theme directory, create the page--views--galleries.tpl.php file. Clear drupal cache and template should work. I used 'galleries' as and example views name.

Solution 3

There's some documentation on template suggestions, and you might be interested in page.tpl.php suggestions. If it's a page view, you could use a path suggestion. So if your view is at, the page.tpl.php file would be named page-photos.tpl.php.

Solution 4

Had a similar problem, which was remedied by putting a .tpl.php in my theme's template folder. The naming convention for a page display of views in drupal 7 is page--path-to-view.tpl.php

Solution 5

In a drupal 7 theme I added a template suggestion in template.php:

function sovon_preprocess_page(&$variables) {   
if(views_get_page_view())   {
    $variables['theme_hook_suggestions'][] = 'page__view';      

See and for more information.

Antonio Lopes
Author by

Antonio Lopes

Web Developer and hopeless at talking about himself.

Updated on August 08, 2020


  • Antonio Lopes
    Antonio Lopes almost 4 years

    How can I create a custom page.tpl.php for a specific view?

    I'm not talking about styling the view itself, just the page where that view gets rendered.

    Thank you.

    @Keith Morgan - It's page.