I've been editing page-user.tpl.php and user-profile.tpl.php in order to customize the way the user profiles look. From within user-profile.tpl.php, the user's profile information is locally available in the $account object, but on the user-profile.tpl.php, it's not available.

i've been stumped on this for a few days ... basically i want to get the account info at a higher level, on the page template. So that on the tracker, contact, etc pages (all of which are displayed through page-user.tpl.php) i can show some of the users' stuff.

All that seems available at this level is the $content variable which is useless to me.

any help please!

thanks
~q

Comments

blueflowers’s picture

I'm a little slow today, but I think this is what you're trying to accomplish:

//put this at the top of page-user.tpl.php
profile_load_profile($account);

then you can see the object by:

print_r($account);

If you're extending the profile with the profile module you can use:

print_r($profile);

or of course the user object by:

print_r($user);

queequeg’s picture

no, that doesn't work as i explained $account and $profile are not within the scope of PAGE-user-tpl.php. At this level only the string $content is available, and that has HTML which has been generated by user-profile.tpl.php.

Why I want to do this? because I want all the user related pages to be customized with the user information (ie contact, tracker, profiles, etc) BEFORE the template spits out the $content variable. I want all the user profile information from the very beginning of the page! Unless I screwed up my drupal theme, it's not working out this way.

I came up with this solution based on the URI that is being accessed, in order to get the user object and grab the user's picture as an example. I Think it will work, but it seems like such a hack solution. The user is already being totally loaded up by the template that comes right after this one, i shouldn't have to load it up twice, right? I just dont know where to look for where the user is actually loaded up here and make it global across ALL of the user pages.

	global $base_url;
	$m_uri =  request_uri();
	
	// user main page: /users/mr-rogers 
	// user edit page: /user/57/edit 
	// tracker: /users/mr-rogers/track
	// file brower: user/57/imce 
	// contact: user/57/contact 
	// parse out the user id/name...
	
	$m_arr = explode("/", $m_uri); // make an array based on the uri
	$m_arr = array_reverse($m_arr); // reverse the array to put the stuff we need at the front of the list ....
	$m_uid = $m_uname = ""; // strings to hold username and user id
	switch($m_arr[0]){
		case "contact":
		case "imce":
		case "edit":
				$m_uid = $m_arr[1];
			break;
		case "track":
				$m_name = $m_arr[1];
			break;
		case "About":
		case "Contact":
		case "General":
		case "Favorites":
		case "Personal":
				$m_uid = $m_arr[2]; // these are profile categories
			break;
		default:
			//$m_name = $m_arr[0]; this is the default page, picture already being shown in profile node, don't load user
			break;
	}
	if($m_uid){ // load the user if we have an ID
		 $m_user = user_load(array('uid' =>  $m_uid));
	} elseif ($m_name){	 // load the user if we have a username
		$m_user = user_load(array('name' =>  str_replace("-", " ", $m_name)));
	}
	
	if($m_user->picture){
		$picture = '<img src="' . $base_url . '/' . $m_user->picture. '" border=0>';
	}
	
	?>
	<?php print $picture; ?>
    <?php print $content; ?>

that's what i came up with, any suggestions to make it better? thx

~q

blueflowers’s picture

Very strange. I have a dev copy of a profile page I'm currently working on. Hopefully it lends something to what you're trying to accomplish. Otherwise, I'm out of ideas (still slow today, got a bad cold lol).

user-profile.tpl.php

<?php
$account_edit = '';
$user_profile_edit = '';
$cooking_profile_edit = '';
profile_load_profile($account);
?>
<?php
if($account->uid == $user->uid){
        print '<div id="user-controls">';
        print l('Edit Account Info','user/' . $user->uid . '/edit');
        print l('Edit Cooking Profile','user/' . $user->uid . '/edit/Cooking Profile');
        print l('Edit User Profile','user/' . $user->uid . '/edit/User Profile');
        print '<br class="clear-both" />';
        print '</div>';
    }
?>
<div id="user-profile-wrapper">
  <?php print $profile['user_picture']; ?>
  <div id="account-info">
  <?php   
    if($account->profile_name != ''): print '<span>Name:</span> ' . check_plain($account->profile_name) . '<br />';
    endif;
    
    if($account->profile_name != ''): print '<span>Cooking Level:</span> ' . check_plain($account->profile_cooking_level) . '<br />';
    endif;
    ?>
        <span>Joined:</span> <?php print check_plain(format_date($account->created, 'custom', 'F n, Y')); ?>
        <br /><?php print l($account->name . '\'s Favourite Recipes','user/' . $account->uid . '/favourites'); ?>
  </div>
</div>
<?php if($account->profile_about_user != ''): ?>
<div id="about-user">
    <h3>About</h3>
    <p><?php print check_plain($account->profile_about_user); ?></p>
</div>
<?php endif; ?>

I take it by using 'page-user.tpl.php' that you'd like a separate style entirely for the page?

If not, use this snippet in your theme.php. This adds template suggestions for nodes

/**
 * Override or insert PHPTemplate variables into the templates.
 */
function phptemplate_preprocess_page(&$vars) {
  $vars['tabs2'] = menu_secondary_local_tasks();
}

function phptemplate_preprocess_node(&$vars) {
  // template name for current node id
  $suggestions = array('node-'. $vars['nid']);
  // additional node template names based on path alias
  if (module_exists('path')) {
    // we already can have a path alias
    if (isset($vars['path'])) {
      $alias = $vars['path'];
    }
    else {
      // otherwise do standard check
      $alias = drupal_get_path_alias('node/'. $vars['nid']);
    }
    if ($alias != 'node/'. $vars['nid']) {
      $add_path = '';
      foreach (explode('/', $alias) as $path_part) {
        $add_path .= !empty($path_part) ? $path_part : '';
        $suggestions[] = 'node-'. $add_path;
      }
      // adding the last one (higher priority) for this path only
      // node-some-long-path-nofollow.tpl.php (not for anchestors)
      $suggestions[] = end($suggestions) .'-nofollow';
    }
  }
  $vars['template_files'] = isset($vars['template_files']) ? array_merge($vars['template_files'], $suggestions) : $suggestions;
}
queequeg’s picture

this is not helpful at all.

what i am seeing is that from the scope of PAGE, there is no connection to the NODE contained within it, which is just printed out in the $CONTENT variable.

THAT is my problem.

The same thing goes for NODE EDIT pages:

I have a scenario where the NODE includes the ability for the user to select a custom layout for the page (gray, black, or white). This needs to be available at the PAGE level in order to have the correct CSS file placed into the head.

in more detailed words ... the user creates a project. the project includes gray/white/black template options for the entire page. Problem is, when the user PREVIEWS their project, the NODE is not available to the PAGE-NODE-EDIT.TPL.PHP file. Nor are the $_POST variables, which is also strange and very annoying.

so when they're previewing their post. they need to be able to see the template in action. That the vaiable is available on the NODE level of the template is useless to me, I need it to be available at the PAGE level.

PLEASE PLEASE PLEASE if anyone knows how to do this let me know. I DONT want to install yet another module. This information ought to be available directly via php.

thank you