国外设计欣赏网站 - DOOOOR.com

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,微信登陆

搜索

[Drupal教程] Drupal7.X, 6.X 自定义用户登陆、注册页面

  [复制链接]
发表于 2-1-2012 22:18 | 显示全部楼层 |阅读模式

照以下步骤进行自定义用户登陆、注册、密码修改页面是相当简单的:首先定义变量;主要的主题注册;创建一个或更多的主题模板;

第一步:在你的主题主目录创建或编辑template.php文件。

第二步:添加一下代码: 代码备注: •以你的主题名称替换”yourtheme”; •$varibles[‘intro_text’]这行是为随后的$varibles数组添加文字说明,在模板中通过$intro_text调用; •这第二行是提供给表单并为$vaiables数组添加代码,在模板中拖过$rendered调用;

第四步:创建模板文件与以上”template”所定义的值相匹配。这样的话,我们仅需要两个文件:user-regeister.tpl.php 和user-register.tpl.php(确认使用英文破折号”-”,而不是下划线”_”)

第五步:粘贴一下代码到user-login.tpl.php。如有必要修改user-login.tpl.php 和 user-register.tpl.php:

第六步:保存文件的到你的饿主题目录第七步:重建缓存。管理路径:Administration > Performance and click on "Rebuild Cache" 现在你的饿用户登陆页面将包含一些新的文本表单处理函数,你可以自定义你所希望的模板文件。


-----------------------------------------------------------------------------------------------------------------------------------

原文如下:http://drupal.org/node/350634



Customizing and Overriding User Login page, Register, and Password Reset in Drupal 6 and 7

Last updated January 26, 2012. Created by Todd Nienkerk on December 23, 2008.
Edited by ptmkennyjacobsonaspiliciousadmin7Log in to edit this page.

Customizing the user login, register, and password reset pages is fairly simple, and uses the following concepts:

  • preprocessing to set variables
  • registration of functions in the theme registry
  • creation of one or more theme templates.

Step 1.
In the site theme directory, create or edit your template.php file.

Step 2.
The first step is to implement hook_theme for your theme. In the template.php file for your theme, look for a function named yourtheme_theme() and modify it to add these return values. If the function doesn't exist, add the following:

For D6:

<?php
/**
* 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),
    ),
  );
}
?>

Notes about that code:

  • Change the function name by replacing "yourtheme" with the name of your theme
  • The template can be the same for all three. The example above uses a different template for each case: user-login, user-register, and user-pass
  • The template names must use a dash, not an underscore
  • Note: It's user_pass not user_password

For D7:

<?php
function yourtheme_theme() {
 
$items = array();
   
 
$items['user_login'] = array(
   
'render element' => 'form',
   
'path' => drupal_get_path('theme', 'yourtheme') . '/templates',
   
'template' => 'user-login',
   
'preprocess functions' => array(
      
'yourtheme_preprocess_user_login'
   
),
  );
 
$items['user_register_form'] = array(
   
'render element' => 'form',
   
'path' => drupal_get_path('theme', 'yourtheme') . '/templates',
   
'template' => 'user-register-form',
   
'preprocess functions' => array(
     
'yourtheme_preprocess_user_register_form'
   
),
  );
 
  return
$items;
}
?>

Notes about the D7 version:

  • The override for the User Password form is omitted for brevity.
  • The 'path' lines tell Drupal where to find the .tpl.php files. This is optional, and in the code above, 'path' tells Drupal to find the files in the templates subdirectory of the theme's base directory.
  • Note the "_form" added to the user_register element.

Step 3.
Now you implement three preprocess functions. There may be more concise ways to code this, but this works very well and is easy to read, so here we go!

For D6:

<?php
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']);
}
?>

Notes about that code:

  • Change the function name by replacing "yourtheme" with the name of your theme
  • The line $variables['intro_text'] adds the text that follows to the $variables array, which gets passed to the template as $intro_text
  • The second line renders the form and adds that code to the $variables array, which gets passed to the template as $rendered

For D7:
The code is even simpler for D7 because we don't need to pass a variable containing the form content we want rendered. The variable exists already in the $vars array and can be rendered in the .tpl.php file.

<?php
function yourtheme_preprocess_user_login(&$vars) {
 
$vars['intro_text'] = t('This is my awesome login form');
}

function
yourtheme_preprocess_user_register_form(&$vars) {
 
$vars['intro_text'] = t('This is my super awesome reg form');
}
?>

The above preprocess functions simply add a variable into the $vars array that is then displayed in the .tpl.php file. Much more complex manipulation of the content of the render array is possible.

Step 4.
Create template files to match the 'template' values defined above. In this case, we only need two: user-login.tpl.php and for D6, user-register.tpl.php (make sure to use a dash, not an underscore) but for D7, user-register-form.tpl.php.

Step 5.
Paste the following into user-login.tpl.php. Modify as necessary for user-register.tpl.php(D6) and user-register-form.tpl.php (D7):

For D6:

<p><?php print $intro_text; ?></p>

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

For D7:

<p><?php print render($intro_text); ?></p>
<div class="yourtheme-user-login-form-wrapper">
  <?php print drupal_render_children($form) ?>
</div>

Note the change to the syntax for causing Drupal to render the form. Also, the D7 sample uses a different class for the div, but that's just a matter of preference.

Step 6.
Save your template.php file to the theme's main directory. Save your .tpl.php files in the same place for the D6 examples, or, in the case of the D7 examples, to the directory you specify in the 'path' element of the $items array.

Step 7.
Rebuild the cache. Go to Administration > Performance and click on "Rebuild Cache" on the bottom of the page.

Now, the user login page will contain the new text from the preprocess function, and the tpl.php file(s) can be modified to suit the site's needs.




|2011-2026-版权声明|平台(网站)公约|手机版|手机版|DOOOOR 设计网 ( 吉ICP备2022003869号 )

GMT+8, 11-11-2025 23:12 , Processed in 0.597809 second(s), 553 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表