Drupal 7 views 3 how would you check the value of the premium content field in a views field theme template. I am trying to test to see if the user is anonymous and the content is premium. I would then print a message for that field instance. If neither those conditions were true I would then print the normal $output variable. Any help would be greatly appreciated.
Comments
Comment #1
anrikun commentedPlease export and post your view here.
Comment #2
ThinkPodDsgn commentedI already have it working with only the php condition to check if the user is anonymous, I am just unsure of the syntax to check if the field belongs to a premium node. I was thinking something along the lines of:
global $user;
if (in_array('anonymous user', $user->roles)) {
if ($node->premium == 0) {
print("Please register to view this content");
}
if ($node->premium == 1) {
print $output;
}
}
else print $output;
Obviously I am using the wrong code but that is the general idea.
Comment #3
anrikun commentedOne correct way to do this is to:
1. Add the
Node : Premium contentfield to your view (even if you don't render it).2. Override
views-view-field.tpl.php(or a more specific version). Inside it, you can get the value of the Premium field by using this code: