Hi mainatainers,

I would like to know how to theme the user relation main page "/relations". I can´t find a theme funktion for it only a user_relationships.tpl.php. Is there a way to call this via the tempalte.php and change it?

Dirk

Comments

jaydub’s picture

http://drupal.org/node/341628

The "Drupal Way" is to do an override. This involves four basic steps:

1. Locate the module responsible for the markup
2. Do one of the following:
* If the module provides a template, copy the .tpl.php file to your theme directory. See Core Templates and Suggestions for a list of core templates.

OR
* Within the module, identify the function that is generating the markup you want to change and copy the function to your theme.
3. Change the HTML code within the copied function or template.
4. Refresh the theme cache.

In Drupal 6 if a module provides a *.tpl.php file you should be able to copy that template file to your theme directory and then modify to your needs. The theming layer will first look for the a *.tpl.php file in your theme directory to use for the module in question before using the module's default *.tpl.php file in the module's directory.

hope that helps.

advseb’s picture

Category: support » bug

Theming doesn't seem to work. I copied the file "user_relationships.tpl.php" to my theme folder and refreshed the template cache. If I now view "My Relationships" page, no relationships are shown anymore. I haven't changed the user_relationships.tpl.php file at all. It seems that the "relationships" variable is not correctly initialised. I think it should get the same result as before if I just copy the user_relationships.tpl.php file to my theme folder.

j0rd’s picture

Title: theme user relation page » Copying user_template.tpl.php into theme folder, breaks user_relationships module.

Same issue. Can confirm this. Something is Wonky with this tpl.php file. Never had this happen before.

If you clear the cache (via devel module) it works on the first load, and on sub-sequent loads the "$relationships" variable in the template is empty. Not sure what the issue is...but it sucks.

I'll provide a temp fix once I figure this out.

PS. The names for one way relationships are confusing. I'm chageing them to

    if($relationship->is_oneway) {
       if($this_user_str == 'requester') {
          $relationship_name = t('They are your ') . $relationship->name;
       }
       else {
          $relationship_name = t('You are their ') . $relationship->name;
       }
    }
    else {
       $relationship_name = t('You are each others ') . $relationship->name;
    }                                                                                                                                                                                                                            
j0rd’s picture

not sure how to fix, so for now i'm editing the user_relationships.tpl.php file directly in the user_relationships module folder.

alex.k’s picture

Hmm, when I copy the template file to the theme directory I actually get a fatal error:

Fatal error: Cannot use object of type stdClass as array in /Users/alexk/projects/user_relationships/ur6/sites/all/modules/user_relationships/user_relationship_elaborations/user_relationship_elaborations.module on line 113

Is it what you're seeing, too?

j0rd’s picture

No, but I also didn't have the elaborations module enabled.

designwork’s picture

Hi all short instruction how to theme this.

1. copy the files user_relationshpis_pending_requests.tpl.php and user_relationships.tpl.php into your theme folder.
2. Copy the function template_preprocess_user_relationships(&$variables) and template_preprocess_user_relationships_pending_requests from user_relationships_ui.templates.inc to your template.php and rename them to mytheme_preprocess_user_relationships(&$variables) etc.
3. refresh the cache at admin/settings/performance.

Now it will work and you can override it.

More theming you can do writing your own module. Like you want to have the friendlist as subtab at user account.

1. Make a little module with an MY.info and an MY.module file see the acording handbookpages how to make this.
2. in your module wirte a menu function like:

/**
 * Implementation of hook_menu().
 */
function MYMODULE_menu() {
	
	$items = array();
	//DG send the userrelation list to user/id/edit only if module exists
	if (module_exists('user_relationships_ui')); {
	
	 $items['user/%user/edit/my_friends'] = array(
    'title'             => t('My friends'),
	'type' 				=> MENU_LOCAL_TASK,
    'access arguments'  => array('maintain own relationships'),
    'page callback'     => 'MYMODULE_relationships_page',
    'page arguments'    => array(1),
    'file'              => 'user_relationships_ui.pages.inc',
	 'file path' => drupal_get_path('module', 'user_relationships_ui'),
	 'weight' => 11,
  );
	} //DG END user relation
	    return $items;
} 

3. you need a user function to make the subtab like:

/**
 * Implementation of hook_user().
 * DG make a sub tab on user edit
 */
function MYMODULE_user($op, &$edit, &$account, $category = NULL) {
	switch ($op) {
    case 'categories':
        $output[] = array('name' => 'my_friends', 'title' => t('My Friends'), 'weight' => 11);
     return $output;
	}
} 

4. In the hook menu we refered to a page in the page callback so we need to generate it like:

/*
 * DG We display the user relationships as subtab
 * this is the page we refer to. Here we call some theme_functions. The theming goes via the tpl files.
 * user_relationships.tpl.php and user_relationships_pending_requests.tpl.php
 */
function MYMODULE_relationships_page($account = NULL, $rtid = NULL) {
  if (!$account) {
    global $user;
    $account = $user;
  	}
  	drupal_set_title(t('My Friends'));
  	$output ='';
  	$output .= '<div id="my_friends_second">';
	$output .= '<p><h3>'. t('Pending') .'</p></h3>'. theme('user_relationships_pending_requests', $account);
	$output .= '</div>';
	$output .= '<div id="meine_freunde_first">';
  	$output .= '<p><h3>'. t('Accepted') .'</p></h3>'. theme('user_relationships', $account, $rtid);
  	$output .= '</div>';
  return $output;
}

So guys hope this helps.

Cheers

Dirk

designwork’s picture

Status: Active » Fixed

I close this thread as it is fixed

Dirk

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

alex.k’s picture

Version: 6.x-1.0-beta9 » 6.x-1.x-dev
Assigned: Unassigned » alex.k
Status: Closed (fixed) » Active

Reopening to fix it properly in CVS. @DesignWork thanks for doing the troubleshooting

alex.k’s picture

Status: Active » Fixed

Committed a fix in CVS. Your solution is still the correct one; I just made it possible to only override the template files, without having to copy preprocess functions.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

ktonini’s picture

This still isnt working for me. Flushing the cache shows the correct template changes, but then on subsequent reloads I get "No Pending Requests."

The "No Pending Requests" string is from the template file though.

Any ideas?

alex.k’s picture

Your problem looks like #465752: drupal_rebuild_theme_registry required for block display I believe, not this bug.

BTW reopen an issue when you comment on a closed one - as it is this doesn't show up in any of issue queues.