【问题标题】:how can i change the entire template of the page according to module in drupal6如何根据drupal 6中的模块更改页面的整个模板
【发布时间】:2013-05-17 12:48:09
【问题描述】:

我在网上查了很多关于 drupal6 主题的区域。网络上的所有教程都说主题模块,这意味着主题化一个小区域或主题化一个小块等。但在我的情况下,当我访问一个模块时,我需要更改页面的整个模板。这在drupal6 中是否可行?

【问题讨论】:

    标签: php drupal drupal-6


    【解决方案1】:

    您可以在主题的 template.php 函数中编写 if 条件。 函数是template_preprocess_page(&$variables)

    并且在这个函数中,写一些if条件。

    For example:
    if($some_condition) {
      $suggestions[] = 'YOUR_CUSTOM_TEMPLATE';
    }
    $variables['template_files'] = $suggestions;
    

    您将拥有您的模板“YOUR_CUSTOM_TEMPLATE.tpl.php”。 应该在主题的模板目录中。

    此外,您可以为内容类型创建自定义模板。 例如对于内容类型的学生,模板将是:

    page--student.tpl.php
    

    【讨论】:

    • 但是如何检查当前模块是这个?
    【解决方案2】:

    从 Drupal 答案 (https://drupal.stackexchange.com/a/18670) 获得:

    如何使用不同的模板创建自定义页面?

    您可以通过建议新的模板为页面使用不同的模板 将使用的模板文件。

    这可以在一个主题中完成,通过编写它的 template_preprocess_page(),或者在一个模块中通过实现 hook_preprocess_page()。 如果您在模块中使用它,则 template_preprocess_page() 需要 重命名了 mymodule_preprocess_page(),其中“mymodule”是模块的简称。

    function mymodule_preprocess_page(&$variables) {
      if (arg(0) == "node" && arg(1) == "1") {
        array_unshift($variables['theme_hook_suggestions'], "page--custom-template");
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-24
      • 1970-01-01
      • 2019-07-28
      • 1970-01-01
      • 2011-01-25
      相关资源
      最近更新 更多