Hi there,

I use a snippet to display certain content (within contemplate) only if user is anonymous using this code.

<?php
//sacar el variable array cargado del usuario
global $user;
//si el uid es igual a cero (es anonimo)
if ($user->uid == 0) {
  //despleje lo que le coresponde al usuario anonimo
  print 'MyContent blah blah';
}
?>

Now I'd like to display that content but only if author is certain role.

I found this post (http://drupal.org/node/379246) that shows how to accomplish this for a block, so I guess the code could be somehow reusable/combined.

Any ideas how to accomplish that?

Comments

ayesh’s picture

This comment looks like the one you need: http://drupal.org/node/379246#comment-1346140

$show_if_author_is = array("premium user", "basic");   // Important to have an array. if this is a single value, use in_array() instead of array_intersect(). 

if ( arg(0)=='node' && ctype_digit(arg(1)) ) {  // if we are on a full node page
  $node = node_load(array('nid' => arg(1)));
  $author = user_load(array('uid' => $node->uid));
  if (count( array_intersect($author->roles, $show_if_author_is) > 0 )) { // this part is changed from original comment!
    print 'MyContent blah blah';
  }
// remove 3 lines below if you don't want anything to show if the author has no role(s) required.
  else {
    print 'else blah blah';
  }
}
return $showit;
manoloka’s picture

mmm ... something similar but not yet there, somehow breaks all the html ...

manoloka’s picture

I meant that the function to disappear seems to be working but it breaks the rest of the html therefore the whole page is looking a mess.

ayesh’s picture

are all HTML tags closed correctly ?
Above code doesn't output anything other than print statements so it's likely that there are some open HTML tags.