Options for displaying OG groups a node is published for on node page?

Posted by Erik Töyrä on Stack Overflow See other posts from Stack Overflow or by Erik Töyrä
Published on 2010-06-10T13:59:40Z Indexed on 2010/06/10 14:02 UTC
Read the original article Hit count: 223

Filed under:
|
|
|
|

What I want

I have several OG groups in which content can be published. I would like to display which OG groups a node has been published for when viewing the node page. Like in "This page is published for: Department A, Department B."

The code snipped below shows the data I have in the $node object in node.tpl.php. This data is generated by the OG module.

Extracted data from $node

    ...
    [og_groups] => Array (
      [993] => 993
      [2078] => 2078
    )
    [og_groups_both] => Array (
      [993] => Department A
      [2078] => Department B
    )
    ...

I know I could loop through the og_groups_both array in node.tpl.php and generate the output from there, but it feels like a quite dirty solution. The ideal solution would be to have a $og_groups variable in node.tpl.php, similiar to how $submitted is used in node.tpl.php (see below).

Example of how $submitted is used

   <?php if ($submitted): ?>
     <div class="submitted"><?php print $submitted; ?></div>
   <?php endif; ?>

Should I use hook_load() in a custom module to insert the new variable $og_groups in $node? What options do I have and which solution would you recommend?

© Stack Overflow or respective owner

Related posts about drupal

Related posts about drupal-6