Community Documentation

Display content according to User Role AND Author Role

Last updated July 9, 2008. Created by abramo on June 21, 2008.
Log in to edit this page.

by abramo

To display content within a node according to User Role AND Author Role - when for example User Role has to be "X" and at the same time Author Role has to be "A" - use the following snippet in your template for the Content Type in question:

<?php
global $user;
$author = user_load(array('uid' => $node->uid));

if ((
in_array('X', $user->roles)) && (in_array('A', $author->roles)))
{
print
"TRUE";
}

elseif ((
in_array('Y', $user->roles)) && (in_array('B', $author->roles)))
{
print
"FALSE";
}
?>

Also "OR" may be employed, if necessary - for example:

<?php

if (((in_array('X', $user->roles)) && (in_array('A', $author->roles))) or ((in_array('Y', $user->roles)) && (in_array('B', $author->roles))))

?>

Use parts and/or combinations of this code according to your needs. Pay attention to the number and placement of brackets.

In place of "TRUE" and "FALSE", of course, you may print anything your little heart desires, at any length - including all sorts of html and drupal code. For example:

<?php

{
print
"
<table>
<tr>
<td>
- The rain in Spain stays mainly in the plain!<br>
- Now, once again, where does it rain?<br>"
;

print
$node->field_details[0]['value'];

print
"
<br>
THE END
</td>
</tr>
</table>"
;
}

?>

Enjoy!




About this page

Drupal version
Drupal 5.x

Site Building Guide

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.
nobody click here