Drupal - display a block for a specific group of users

I have about 6 different groups, for example Team A, Team B, etc. I would like to display a block for one of these groups. Thought something like checking if gid = X users were logged and then displayed a block. Thus, I can configure 6 different blocks for all targeting to different groups, so that when a user logs in, he displays the corresponding block for them. Does this make sense? How do I implement it?

+3
source share
2 answers

Depending on your exact setup, it looks like Context might help you.

Here is how you can do it.

  • Create 6 separate blocks.
  • Download and install the context module
  • admin/structure/context/add
  • , "", , . , , .
  • ( 6). .

CERTAIN CONTEXTS. ( ) ( ) node ..

, Organic Groups , . , "" " ", . , "".

, !

+1

, , .

<?php 
   global $user;
   $uid = $user->uid;
   $result = db_query ( "SELECT * FROM {og_membership}
   WHERE etid = :uid
   and entity_type = 'user'
   order by gid DESC", array (':uid' => $uid ) );

   foreach ( $result as $row ) {
     $gid = $row->gid;
     break; 
   }
?>    

<?php if ($gid == "GROUP ID HERE"): ?>

(load block here)

<?php endif; ?>
+1

All Articles