Howdy,

was wandering if could be possible to start from Contemplate to add more fields based on roles (other than the 2 default Teaser/Body), so to allow a top-down filter to content (as opposed to the bottom-up filter provided by other access-limiting modules as TAC, CAC, OG, simple acces,..), based on role of author.

Imagine to have:

  • 3 roles (Silve, Gold, Platinum)
  • a 'Listing' content-type composed of 12 fields

and you need to let authors fill in all the fields on submission form, but then show only some of them to the visitors on node output depending on role of the author, so for example Silver authors can show 4 fields, Gold can show 8 and Platinum all 12.

Does this make sense and would be somehow feasable adding more role-based templates?

thx

Comments

jjeff’s picture

Status: Active » Closed (works as designed)

I think that you can do this with the current module without any updates.

You would just write into your template something along these lines:

global $user;
if (in_array('gold', $user->roles) ||  in_array('platinum', $user->roles)) {
  print $node->field_whatever[0]['view'];
}

I'm going to mark this as "by design" but let me know if I'm missing something in your request.

jjeff’s picture

Ooop... that would be the code for a node.tpl.php -type file... For contemplate you would use this:

global $user;
if (in_array('gold', $user->roles) ||  in_array('platinum', $user->roles)) {
  print $field_whatever[0]['view'];
}

-Jeff

marcoBauli’s picture

humm...and this will filter by role of author (top-down), NOT role of user actually browsing the node (bottom-up), right? (sorry if i repeat myself, but this is the tricky bit..)

jjeff’s picture

The global $user variable represents the user who is *viewing* the page. So the above example filters for the visiting user.

To filter based on the author's roles, you'd do this type of thing:

$account = user_load(array('uid' => $uid));
if (in_array('gold', $account->roles) ||  in_array('platinum', $account->roles)) {
  print $field_whatever[0]['view'];
}
marcoBauli’s picture

Jeff, you are the man!

ohh i was chasing such functionality since such long time...!

it works! Thank you! :D

PS: love the mod by the way. Maybe in a future it could turn into a Drupal *powertool* for theming nodes, similarly to what Category is for structuring or Views for publishing?!

Imagine adding:

  • Variables listing: listing all node variables (not only CCK's) to pick from.
  • Ordering: possibility to weight fields (i.e. à la Views: move up, down, top, bottom).
  • Filtering: for example by role of author, by role of visitor, by creation time,...
  • Styling: defining colours and basic styles (plain, italic, bold) for fields.

well, maybe i'm just flying, but this would be nice indeed..

cheers

1kenthomas’s picture