1

i already searched all relevant drupal sites - but without success. I have to create a own template file for the "edit user profile" site of the module Profile2.

As far as i know, i have to hook the new templatefile in the template.php of my theme - but what keywords and syntax do i need to accomplish that?

Every hint would be great! Thanks.

3

I did this way to create my own "edit user profile" for profiles of profile2 module.

function customtheme_theme() {    
    $items = array();
    $items['user_profile_form'] = array(
        'render element' => 'form',
        'path' => drupal_get_path('theme', 'customtheme') . '/templates',
        'template' => 'user-profile-form',
        'preprocess functions' => array(
             'customtheme_preprocess_user_profile_form'
        ),
    );
    return $items;
}
  • I put customtheme_theme() function into my template.php file of customtheme theme. (a custom theme that i used for my website)
  • After that i created the template file user-profile-form.tpl.php and placed in the templates folder of my theme. The customtheme_preprocess_user_profile_form function you can use that for changing some variables before render the profile form or if you dont need any changes you can remove the preprocess_functions.
  • After add the customtheme_theme(), create user-profile-form.tpl.php template. You have to clear cache and you can see the layout change for user-profile-form.
| improve this answer | |
1

Thanks for this very detailed reply. I made all entrys in the template.php and user-profile-form.tpl.php and cleared all cache multiple times. Unfortunately the edit site does not change. Iam confused about the $items['user_profile_form'] keyword - is there any reference, because in other forums i read something about $items['user_profile2_edit']?

I keep on trying and will reply as soon as it works! Thx

| improve this answer | |
  • So you are asking about separate tpl file for profile2 profile edit page ? – mohit_rocks Apr 8 '13 at 11:14
  • Exactly! I guess Stone Vos answer should work ... but iam still searching the reason why the new tpl file doesnt show up. – crashedsun Apr 8 '13 at 12:00
  • Have you checked this question: drupal.stackexchange.com/questions/31203/… – mohit_rocks Apr 8 '13 at 12:14
  • Hm, i checked it out, but the self-answered question is about another module. Approach 2 is very similar to Stone Vos reply and i cant detect any significant differences :/ – crashedsun Apr 9 '13 at 13:56
  • Did you solve the problem? – Stone Vo Apr 16 '13 at 21:16
1

This is how I accomplished different template files for each Profile2 Edit Page.

First, form_alter to set up the form #theme properly

function THEME_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'user_profile_form') {
    if ($form['#user_category'] === 'writers') {
      $form['#theme'] = 'profile2_writers_edit_form';
    } else if ($form['#user_category'] === 'secondary') {
      $form['#theme'] = 'profile2_secondary_edit_form';
    } else if ($form['#user_category'] === 'main') {
      $form['#theme'] = 'profile2_main_edit_form';
    }
  }
}

Then you can set up the templates this way

function THEME_theme() {
  return array(
    'profile2_writers_edit_form' => array(
      'arguments' => array(
        'form' => NULL,
      ),
      'template' => 'profile2-writers-edit',
      'render element' => 'form',
    ),
    'profile2_secondary_edit_form' => array(
      'arguments' => array(
        'form' => NULL,
      ),
      'template' => 'profile2-secondary-edit',
      'render element' => 'form'
    ),
    'profile2_main_edit_form' => array(
      'arguments' => array(
        'form' => NULL,
      ),
      'template' => 'profile2-main-edit',
      'render element' => 'form',
    ),
  );
}

Now all you have to do is add the files to your theme folder and clear cache. In this case I ended up with the following files for Profile2

profile2-writers-edit.tpl.php
profile2-secondary-edit.tpl.php
profile2-main-edit.tpl.php

A basic tpl should look something like this

<article id="node-user-edit" class="profile2-user-edit writers-profile">
  <?php print drupal_render_children($form); ?>
  <?php print drupal_render($form['#submit']); ?>
</article>

Print fields singularly like so

<?php print drupal_render($form['FIELD_NAME']); ?>
| improve this answer | |
  • This is a good example IMO. I have been trying to work out how I need to set up 3 custom Edit pages for 3 member types. Your example makes good sense and explains what to do by example. You should put your example on the drupal.org site as no other clear concise examples show how to add 'more than 1' profile2 edit page. Thanks for the effort & time amigo. – Paul B Mar 9 '14 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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