Closed (fixed)
Project:
Views (for Drupal 7)
Version:
6.x-2.8
Component:
Miscellaneous
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
19 Feb 2010 at 05:03 UTC
Updated:
5 Mar 2010 at 17:00 UTC
I am trying to display one thing to the author of the node and something different to everyone else viewing it:
global $user;
if ($user->uid == $node->uid)
{ print t('you are THE AUTHOR'); }
else {
print t('you are NOT the author');
}
but I get the negative 'NOT the author' message in all cases, even when the author of the node is the currently logged in user.
The possible catch is that I am trying to use this as the "empty text" of a view.
This should be easy... is there something wrong with my php? Thanks
Comments
Comment #1
merlinofchaos commentedNo variables are filled in for you (and cannot be) in the PHP filter. So $node is not a valid value, and therefore $node->uid is NULL. You have to find and load the node to do this.
You can use $view = views_get_current_view(); to get the view and look at $view->result or look at $view->arg perhaps.
Comment #2
boogsbobo commentedThanks for the quick response,
Instead of going that route, I decided just to make two versions of the block.
Both are identical, except for the "empty text" sections. The first version is aimed at logged-in node authors, and the second block is for everyone else.
I added the block directly into my node-type.tpl.php as follows:
It is working perfectly.