Custom page.tpl.php for viewing Drupal

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

I'm not talking about styling the view itself, just the page on which that view is displayed.

Thank.

@Keith Morgan - This page.

+3
source share
8 answers

You can create a template file for the theme of almost any aspect of the presentation output. In your case, you want to create your own template for displaying the page.

" ". , (, view-view - example - page.tpl.php), (, view-view-fields - example --page.tpl.php) ..

, /sites/all/modules/views/theme, , .

, "", , . .

, .

+5

Per Allartk
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';
    }
}

- views - galleries.tpl.php. Drupal. 'galleries' name.

+7

, page.tpl.php. , . , http://www.example.com/photos, page.tpl.php page-photos.tpl.php.

+4

, .tpl.php . drupal 7 - page-path-to-view.tpl.php

+2

drupal 7 template.php:

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

. http://api.drupalize.me/api/drupal/function/views_get_page_view/7 http://drupal.org/node/223440#custom-suggestions .

+2

, , page_manager_get_current_page() , , , ( , ..).

+1

sillygwailo, , :

function YOUR-THEME-NAME_preprocess_page(&$vars) {

 //allow template suggestions based on url paths.  
 $alias = drupal_get_path_alias(str_replace('/edit','',$_GET['q'])); 
 if ($alias != $_GET['q']) { $suggestions = array();
 $template_filename = 'page'; 
 foreach (explode('/', $alias) as $path_part) {
 $template_filename = $template_filename . '-' . $path_part; 
 $suggestions[] = $template_filename;
 } 
 $alias_array = explode('/', $alias);
 $variables['template_files'] = $suggestions; 

, www.example.com/photos, -photos.tpl.php , drupal .

+1
source

If this verified answer doesn’t work (because it didn’t do it for me), you can create a page - (urlname) .tpl.php and then create your own theme, no matter how you like it. You can then import your view in one of several ways ...

       print render($page['content']);  

or

$ view = views_get_view ('viewname'); print $ view-> execute_display ('default', $ args);

$ args is just an array and can be empty. You can simply completely abandon it.

0
source

Source: https://habr.com/ru/post/1778160/


All Articles