[转]Drupal6模块模板重写

根据drupal官方网站http://drupal.org/node/350634的文章。

自定义用户登录,注册和密码重置页面都很简单,具体步骤如下:

步骤一:在主题所在的文件夹,编辑template.php文件,寻找名为yourtheme_theme(yourtheme是指你使用的主题的名字)的函数,并进行如下修改:

    /**
    * Registers overrides for various functions.
    *
    * In this case, overrides three user functions
    */
    function yourtheme_theme() {
      return array(
        'user_login' => array(
          'template' => 'user-login',
          'arguments' => array('form' => NULL),
        ),
        'user_register' => array(
          'template' => 'user-register',
          'arguments' => array('form' => NULL),
        ),
        'user_pass' => array(
          'template' => 'user-pass',
          'arguments' => array('form' => NULL),
        ),
      );
    }

注意:

用你的主题名称替换‘yourtheme'

三个页面可以使用相同的模板,在本列中使用了三种模板(user-login、user-register和user-pass)

模板的名称中使用短划线,不是下划线

注意是user-pass而不是user-password

步骤二:

接下来,写三个预处理函数,如下:

    function yourtheme_preprocess_user_login(&$variables) {
      $variables['intro_text'] = t('This is my awesome login form');
      $variables['rendered'] = drupal_render($variables['form']);
    }
      
    function yourtheme_preprocess_user_register(&$variables) {
      $variables['intro_text'] = t('This is my super awesome reg form');
      $variables['rendered'] = drupal_render($variables['form']);
    }
      
    function yourtheme_preprocess_user_pass(&$variables) {
      $variables['intro_text'] = t('This is my super awesome insane password form');
      $variables['rendered'] = drupal_render($variables['form']);
    }

注意:

用你的主题名称替换'yourtheme'

数组 $variables中变量$variables['intro_text']的文字内容将通过$intro_text传递到页面

步骤三:创建模板文件user-login.tpl.php和user-register.tpl.php来对应上面定义的'template',并在这个文件中添加一下代码:

    <p><?php print $intro_text; ?></p>
      
    <div class="my-form-wrapper">
      <?php print $rendered; ?>
    </div>

步骤四:保存文件,并清空缓存

原文地址:https://www.cnblogs.com/catcat811/p/1942836.html