By thepaul on
I would like to show certain blocks to users only when they are looking at thier own profile, and different blocks when they are looking at someone elses.
I am sure there is a way to do this using the following setting in the block configuration:
"Show if the following PHP code returns TRUE (PHP-mode, experts only)."
I basically need a PHP snippit that does the following:
If username = the username in the path to this profile page
then
show the block
Can anyone help me out here?
Comments
In the PHP visibility you
In the PHP visibility you can check if arg(1) (the user id in the URL) is the same as the currently logged in user $user->uid.
So something like:
--
Ixis (UK) providing Drupal consultancy and theme design. Check the portfolio.
--
Ixis (UK): Drupal support, Drupal hosting.
Something like this may help
Something like this may help. Basic logic is to only show block when viewing profile page. By replacing question marks with approriate values can be used to enable block when viewing either own profile or another persons.
<?php
global $user;
if ( arg(0) == 'user' && is_numeric(arg(1)) ) {
$uid = arg(1);
We are viewing a profile page
if ( $user->uid == $uid ) {
// Viewing own profile page
// Return approriate value
// True to view, false otherwise
return ??;
}
else {
// Viewing someone elses profile page
// Return approriate value
// True to view, false otherwise
return ??;
}
}
else {
// Not viewing a profile page
return FALSE;
}
Thank you both for the quick
Thank you both for the quick replies, this is a great help. One more question in the same vein:
How would I go about displaying the user->picture in a block on the profile page?
For instance I am viewing userID 1's profile. I would like his avatar to display in a block... if I am viewing userID3's profile I would like her avatar to display in the same block.
Thanks again.
Given an user id, this will work
Given an user id, this will work
Thanks for the reply nevets,
Thanks for the reply nevets, but I think my issue is a bit more complex because I am using pathauto/url aliases.
I found an old post that deals with the same issue, though I am stll trying to find an aswer!
I will continue my search on that old thread though:
http://drupal.org/node/166818
You don't say why it might be an issue
You don't say why it might be an issue but if you are aliasing 'user/N' where N is a user id (uid) the arg() function returns the unaliased path.
nevets, thanks for leading
nevets, thanks for leading me in the right direction. The following snippet appears to be working for me.