[转]Drupal6模块模板重写

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

 

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

 

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

 

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
* 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

 

步骤二:

 

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

 

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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',并在这个文件中添加一下代码:

 

 

?
1
2
3
4
5
<p><?php print $intro_text ; ?></p>
   
<div class = "my-form-wrapper" >
   <?php print $rendered ; ?>
</div>

 

 

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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值