【问题标题】:applying specific theme to particular form in Drupal 7在 Drupal 7 中将特定主题应用于特定形式
【发布时间】:2012-03-20 15:25:54
【问题描述】:

我想为 Drupal 中的特定表单添加特定主题。例如,假设我想将名为 menu_edit.tpl.php 的模板应用到 menu_edit_menu 表单。如何才能做到这一点。这可以使用 Hook_theme() 函数来实现吗?任何人都可以为我提供有关如何执行此操作的代码 sn-p。在这方面的任何帮助将不胜感激。

【问题讨论】:

    标签: drupal-7 drupal-modules drupal-theming


    【解决方案1】:

    您可以通过在 hook_theme 中使用 template 键来完成此操作

    /**
    * Implementation of hook_theme().
    */
    function yourmodule_theme() {
      return array(
       'variables' => array(1) , 
       'template' =>  'my_template' , 
      ) ; 
    }
    

    在本例中,您可以在同一模块目录中创建my_template.tpl.php

    follow this tutorial for more details

    祝你好运

    【讨论】:

    • 非常感谢。我一直在寻找这个解决方案..这很好..但你能解释一下为什么我们使用“变量”吗?
    • 无论如何您都可以更改此名称,但此名称应与从参数传递的名称相同,例如 function template_preprocess_article_node_form(&$vars) 在这种情况下您应该使用 $vars 而不是 $variables跨度>
    猜你喜欢
    • 2017-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多