Frustrated! Can't embed regions, blocks, views, anything in user_profile.tpl.php
Hey all
I have an extremely frustrating problem with embedding pretty much anything in my custom user profiles. Maybe there's something not apparent here, maybe you can see it.
In my template.php I have this callback. I'm told this is standard fare for profile customization.
function phptemplate_user_profile($user, $fields = array()) {
// Pass to phptemplate, including translating the parameters to an associative array. The element names are the names that the variables
// will be assigned within your template.
/* potential need for other code to extract field info */
return _phptemplate_callback('user_profile', array('account' => $user, 'fields' => $fields));
}My templating is done via path:
function _phptemplate_variables($hook, $vars = array()) {
switch ($hook) {
case 'page':
if (drupal_is_front_page()) {
$suggestions[] = 'page-index';
}
if (module_exists('path')) {
$alias = drupal_get_path_alias($_GET['q']);
if ($alias != $_GET['q']) {
$suggestions = array();
$template_filename = 'page';
foreach (explode('/', $alias) as $path_part) {
$template_filename = $template_filename . '-' . $path_part;
$suggestions[] = $template_filename;
}
}
$vars['template_files'] = $suggestions;
} global $user;
break;I have two templates, a page-user.tpl.php and a user_profile.tpl.php.
In page-user.tpl.php, all I have is
<? print $content ?>In my user_profile.tpl.php I have all my customizations for my profile, such as markup, scripts, dumping field content etc, which works fine.
Now, in user_profile.tpl.php, if I try to embed a block with module_invoke, or try print out a region which I know contains a block or content, such as <? print $header ?> , I get nothing whatsoever. No markup, no content, nothing.
However, if I backtrack, go to page-user.tpl.php and place <? print $header ?>, voila, it works. Why can't user_profile.tpl.php see blocks, views, etc? but page-user.tpl.php can??

Wish that i could help
http://drupal.org/node/165114
Lotsa interesting things to do with user-profile.tpl.php, and you brought attention to invoking blocks in customized user profile
If any solution, i will link to this thread from the one i created :)
Cheers, and happy new year
Have you had the same
Have you had the same problem Muslim Guy?
Happy New Year to you too :)
Not yet :)
Was `thinking' about BLOCKS and regions too, but havent tried anything concrete. Did use a lot of module_invoke, iframe, and Javascript pagination and tabs
*i am not able to program PHP, but can at least copy/emulate existing Drupal APIs and whatnots into userprofile
Hmm, I will post any code if
Hmm, I will post any code if I figure out how to get it working
I got this to work, for
I got this to work, for instance with the ad.module, I placed the ads I wanted into a region called 'ad' and used this following code in user_profile.tpl.php
<?phpprint theme('blocks', 'ad');
?>
Different tpl files have different variables available to them .
your page.tpl file (and your user-page.tpl file) have a totally different set of variables available for use than your user_profile.tpl file. THis page will list the variables you can access in a page.tpl http://drupal.org/node/11812 ... your user_profile.tpl file only has access to the variables you are passing in your _phptemplate_callback call - in this case just $account and $fields.
What exactly are you trying to achieve? Will a combination of user-page.tpl and user_profile.tpl work? Personally I don't like using multiple page.tpl files as it makes maintaining your theme a bit of a pain, although there are obviously cases where they have to be used.
Cheers,
Mike,
Computerminds offer Drupal development, consulting and training
Hey Mike, I was under the
Hey Mike,
I was under the impression that user_profile.tpl.php was embedded in page-user.tpl.php to some degree, for if I remove
<? print $content ?>line from page-user.tpl.php, I do not get anything appearing at all.It's a lot easier to customize the user_profile for me because I can access the fields and move them around as I see fit, I can't figure out how to do this in page-user.tpl.php
You are looking in the right place,
You are looking in the right place, but need a little more debugging.
The assorted tpl.php files are nested, and your setup is mostly right, but due to PHP scoping rules, and also to avoid conflict, they only have access to the fields they have explicitly been given passed in as an argument.
try print_r($fields) in your func, or (IIRC) print_r($vars) in your template.
page_xxx.tpl.php files are the ones that have access to the entire pages blocks and things - page-level elements are not directly available to sub-templates. Which is a little annoying, but, as above, it's about scoping and conflicts.
conversely, your page template probably doesn't have good visibility of the profile data ... unless you work hard to retrieve it. page-level templates usually trust that their $content has already been laid out internally.
It does all fit together, and it sounds like you are doing the right thing. Just try dumping some diagnostics or tracing the phptemplate engine to really grok it (and learn a bunch more short-cuts in that cool code.)
.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/
Hey Dan, thank you once
Hey Dan, thank you once again for spending time with me.
print_r($vars) or print_r($node) doesn't work in either user_profile.tpl.php, nor page-user.tpl.php for some reason. Any suggestions for a deeper debug?
$node is not available in
$node is not available in user_profile - it's not a node.
By $vars I may have meant $variables
http://api.drupal.org/api/function/_phptemplate_render/5
Or $fields in the func
.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/
Hmm, still no luck. I'll
Hmm, still no luck. I'll have to figure out a different way to embed blocks and regions in user_template.tpl.php. Probably should have used nodeprofile or something rather than the default profiles.
Block regions in user profile and nodes is possible
Hey: just posted a solution on another topic:
You can actually add blocks inside user profiles and nodes. Assuming you have setup your block regions like so (in your template.php file):
function phptemplate_regions() {return array(
'left' => t('left sidebar'),
'right' => t('right sidebar'),
'test_region' => t('test regioin')
);
}
You can use _phpteplate_variables to pass block regions onto nodes and the user profile. example:
function _phptemplate_variables($hook, $vars = array()) {switch ($hook) {
case 'user_profile': // If you setup the user_profile.tpl.php file for custom user profiles (see handbook)
$vars['test_region'] = theme('blocks', 'test_region'); // If your block region is named 'test_region'
break;
case 'node': // for nodes only
$vars['test_region'] = theme('blocks', 'test_region'); // again, if your block region is named 'test_region'
break;
}
}
---
I work here: Raincity Studios.com
I hang out here: Steve Krueger.com