Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Templates Drupal7:如何为多种内容类型创建一个节点页面?_Templates_Preprocessor_Content Type - Fatal编程技术网

Templates Drupal7:如何为多种内容类型创建一个节点页面?

Templates Drupal7:如何为多种内容类型创建一个节点页面?,templates,preprocessor,content-type,Templates,Preprocessor,Content Type,在我的网站中有8种内容类型,其中4种结构相同,不同的只是名称。我想为它们创建一个节点页面,但我想为每个节点创建一个.tpl.php文件效率很低。我使用以下方法为特定内容类型创建节点页面: 创建页面并将其重命名为page--node--Machine-Name-of-ContentType.tpl.php 将此函数添加到template.php 函数ThemeName_预处理_页面(&$variables) { } 有没有办法为多个内容类型创建一个节点页面 function theme_prepr

在我的网站中有8种内容类型,其中4种结构相同,不同的只是名称。我想为它们创建一个节点页面,但我想为每个节点创建一个.tpl.php文件效率很低。我使用以下方法为特定内容类型创建节点页面:

  • 创建页面并将其重命名为page--node--Machine-Name-of-ContentType.tpl.php

  • 将此函数添加到template.php

    函数ThemeName_预处理_页面(&$variables) {

    }

  • 有没有办法为多个内容类型创建一个节点页面

    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;
        }
    }
    
    将使用page--alt.tpl.php文件

    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;
        }
    }