Вопрос

there are 8 content types in my website and 4 of them have the same structure and the difference is just their name. I want to create a node page for them but I guess it is inefficient to create one .tpl.php file for each one. I use the following method to create node page for a certain content type:

  1. create page and rename it to page--node--Machine-Name-of-ContentType.tpl.php

  2. add this function to template.php

    function ThemeName_preprocess_page(&$variables) {

    if (isset($variables['node'])) 
    {
        $suggest = "page__node__{$variables['node']->type}";
        $variables['theme_hook_suggestions'][] = $suggest;
    }
    

    }

Is there any way to create one node page for a multiple content types?

Это было полезно?

Решение

function theme_preprocess_page(&$vars) {
  if (isset($vars['node']->type)) {
    switch ($vars['node']->type) {
      case 'news':
      case 'blog':
      case 'event':
      case 'page':
        $vars['theme_hook_suggestion'] = 'page__alt';
        break;
    }
}

will use page--alt.tpl.php file

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top