简体   繁体   English

在Drupal 7中为不同的页面组创建multipe page.tpl

[英]Creating multipe page.tpl for different page groups in Drupal 7

the site I'm currently building in Drupal is split into two very different areas, both structured quite differently. 我当前在Drupal中构建的站点分为两个截然不同的区域,两个区域的结构都完全不同。 My solution is to build two different page.tpl pages. 我的解决方案是建立两个不同的page.tpl页面。 Does anyone know what the easiest method is to implement this in Drupal 7. Is it a naming convention process like the node.tpl page or will I need to insert a preprocess function in the template.php page. 有谁知道最简单的方法是在Drupal 7中实现此方法。它是像node.tpl页面这样的命名约定过程,还是需要在template.php页面中插入预处理功能。

Cheers for any help! 为任何帮助加油!

You could also attach a preprocess function in your template.php file. 您还可以在template.php文件中附加预处理功能。 Something like the following: 类似于以下内容:

function yourthemename_preprocess_page(&$vars, $hook) {  
    if (isset($vars['node'])) {  
        // If the node type is "blog_madness" the template suggestion will be "page--blog-madness.tpl.php".  
        $vars['theme_hook_suggestions'][] = 'page__'. $vars['node']->type;  
    }  
}

Have a look at this page: http://drupal.org/node/1089656 看看此页面: http : //drupal.org/node/1089656

It explains the naming schema for your template files and how to extend the template suggestions. 它说明了模板文件的命名架构以及如何扩展模板建议。

In your case, you'll have to implement the theme_get_suggestions() function. 对于您的情况,您将必须实现theme_get_suggestions()函数。 In this function you can check the path arguments to determine which kind of page you need to display and add the appropriate suggestions. 在此功能中,您可以检查路径参数以确定需要显示哪种页面并添加适当的建议。

You can use the Context module. 您可以使用上下文模块。

Within a given context, you can add the "Template suggestions" reaction. 在给定的上下文中,您可以添加“模板建议”反应。 This will allow you to specify additional template files that will override the defaults. 这将允许您指定其他模板文件,这些文件将覆盖默认设置。 See the issue in the Context queue, Add a "Template suggestions" reaction , for details. 有关详细信息,请参见上下文队列中的问题, 添加“模板建议”响应

With this approach, it's not necessary to write any module code. 使用这种方法,无需编写任何模块代码。

function your_theme_preprocess_node(&$variables) {
  // Add specific templates.
  foreach ($variables['theme_hook_suggestions'] as $theme_suggestion) {
    $variables['theme_hook_suggestions'][] = $theme_suggestion . '__' . $node->view_mode;
  }
}

also you can call preprocess function here if adding this code 如果添加此代码,您也可以在此处调用预处理功能

  // Run specific preprocess function.
  $preprocess = 'your_theme_preprocess_node_' . $node->type . '__' . $node->view_mode;
  if (function_exists($preprocess)) {
    $preprocess($variables);
  }

in this case you can use different templates not only for node types but for different view modes too 在这种情况下,您不仅可以对节点类型使用不同的模板,还可以对不同的视图模式使用不同的模板

I don't get it . 我不明白。 If you want to use two different template files then just create two different content types and you can by pass all this coding. 如果要使用两个不同的模板文件,则只需创建两个不同的内容类型,就可以通过所有这些编码。

let me know if you need further help. 让我知道您是否需要进一步的帮助。 vishal 维沙尔

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM