Pulling my hair out after googling all day to solve this.

I am using a corolla subtheme on drupal 7. I am trying to override the user account edit page in a template file.

For that I am using the default user-profile.tpl.php that comes with core's user module.

But without preprocessing the file won't be recognized by my theme. So I googled here and there and came up with the following:

function mytheme_theme(&$existing, $type, $theme, $path){

  $hooks = array();
    // Make user-profile.tpl.php available
    $hooks['user_profile_form'] = array (
       'render element' => 'form',
       'path' => drupal_get_path('theme','mytheme'),
       'template' => 'templates/user-profile',
       'preprocess functions' => array('mytheme_preprocess_user_profile_form'),
  return $hooks;

function mytheme_preprocess_user_profile_form(&$vars) {
  $args = func_get_args();
  $form_state['build_info']['args'] = $args;
  $vars['form'] = drupal_build_form('user_profile_form', $form_state['build_info']['args']);

My php is at a level copy/paste + minor adjustments with a lot frustration.

This preprocessing makes my site read the user-profile.tpl.php, but I can't access the array $user_profile. Instead fields are in the array $form, which misses some fields I need, and all fields miss their default values which should come from the user whose account is shown.

This way I can't rebuild the default password-inputboxes and the 2 new password-inputboxes, and I need a lot of extra php to supply the values for all fields.

I am missing something here, but my knowledge won't go that far that I know what to change, and my google-fu is depleted. I think I need to change some things in the preprocessing-code, so that the array $user_profile is loaded and all the fields have the correct values allready.

How to accomplish this?

How can I make this to work?

  • Aren't you mixing 2 different parts / pages, user_profile (user/%user) vs user_profile_form (user/%user/edit) ? Dec 3, 2013 at 18:36
  • I don't know, do I? I am overwriting user/%user with pagemanager and views, I got that covered, but that's just displaying information. I only want to style/theme user/$user/edit.
    – Marcel
    Dec 3, 2013 at 19:46

1 Answer 1


In order to have the $user_profile renderable array available within your tpl, you can use the same logic used by Drupal user core module.

Build the content for a user object, loop through each field and assign it to the $user_profile variable.

In your case, it would something like this:

function mytheme_preprocess_user_profile_form(&$vars) 
    // load user
    $account = user_load(arg(1));

    if (!$account) {
        // user not found

    // retrieve all profile fields and attach to $account->content.

    // loop through each field attached to the user object
    $vars['user_profile'] = array();
    foreach (element_children($account->content) as $key) {
        // add it to the $user_profile variable, which will be available in tpl
        $vars['user_profile'][$key] = $account->content[$key];

    $args = func_get_args();
    $form_state['build_info']['args'] = $args;
    $vars['form'] = drupal_build_form('user_profile_form', $form_state['build_info']['args']);
  • 1
    Let me see if I understand this: Preprocessing is just loading variables. The way I can use them in a tpl.php file is just a matter of how I name them in template? Here you say $vars['user_profile'], but if I named it $vars['crazyname'] I could access them as render($crazyname) in the tpl.php file?
    – Marcel
    Dec 5, 2013 at 9:28
  • Yes, exactly :) Dec 5, 2013 at 11:32
  • SOLVED thx! I only needed to point to the location template file in template.php with 'arguments' => array('form' => NULL) in it.
    – Marcel
    Dec 12, 2013 at 9:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.