Search code examples
phpfunctiondrupaldrupal-7drupal-theming

Error when creating a custom page in Drupal 7


(Using Adaptive Theme) I want a new and custom user login page. So, put this code in my template.php:

function mythemename_theme() {
  $items = array();
  // create custom user-login.tpl.php
  $items['user_login'] = array(
  'render element' => 'form',
  'path' => drupal_get_path('theme', 'mythemename') . '/templates',
  'template' => 'user-login',
  'preprocess functions' => array(
  'mythemename_preprocess_user_login'
  ),
 );
return $items;
}

Changed mythemename to my custom theme name. And created user-login.tpl.php files and put this code:

<?php 
  print drupal_render($form['name']);
  print drupal_render($form['pass']);
  print drupal_render($form['form_build_id']);
  print drupal_render($form['form_id']);
  print drupal_render($form['actions']);
?>

Lastly, cleared my site cache. But when i click mysite.com/user login page not changed.

Where the error am I doing? How can I solve this problem?


Solution

  • Try putting this in template.php, change mythemename to theme name, and flush the cache.

    function mythemename_theme($existing, $type, $theme, $path){
        $hooks['user_login']=array(
        'render element'=>'form',
        'template'=>'templates/user-login',
        );
        return $hooks;
    }
    

    Then in templates/user-login.tpl.php insert:

    <?php
    print render($form['name']);
    print render($form['pass']);
    print render($form['form_build_id']);
    print render($form['form_id']);
    print render($form['actions']);
    ?>
    

    or

    <?php print drupal_render_children($form) ?>