I am looking for a way to theme content that is in some ways a lot simpler than themes and a little bit more flexible in one respect. I run a site with several groups and I have to make it instantly clear were content originates from. This can of course be done by using themes, but it seems that this is not entirely what I need for two reasons:

- themes is too powerful: I only want the heading of the node to include a tiny logo, nothing else needs to change

- themes do not seem to work with teaser list, especially on the the frontpage, even using views - it would be very helpful if my user could instantly see that this teaser originates from that group and the other teaser from the other one

What might do the trick is to use the node template, have it check what group the node belong to and then display the group logo for that node, be it teaser or complete view of the node. Is there a way to do this using PHP (if so, what variables would I have to look at), or is there another approach I could try?

Thanks very much for your comments on this!

Comments

.carey’s picture

I have a site setup where the nodes are themed based on content type (and taxonomy).

This may help: http://drupal.org/node/17565

Anonymous’s picture

Thanks for the link! Do you have any idea about how to make node & teaser of the node appear differently not based on content type or taxonomy, but rather according to the organic group the node belongs to? Groups can of course have themes, but that does not seem to affect the teaser on the front page...

.carey’s picture

You could use the taxonomy_theme module (http://drupal.org/project/taxonomy_theme).

I didn't use this module because it just adds one more module to the list, and to keep up with. And, to me, it seems there's more control over node theming with the node-$type.tpl.php method.

Cheers,

Carey

Anonymous’s picture

I am also not keen on adding more modules, unless necessary (we already have way too many), so I'd much rather go with the template approach, as indicated in my posting. The only problem I have with this is how to identify which group the node belongs to. I do not want a different appearance based on taxonomy or node type, only based on the group the node belongs to. This works well using themed groups, but this does not affect the teaser on the front page.

I only want to add a tiny logo to the heading of *every* node, be it teaser or full node, frontpage or within the group, but for that I need a PHP variable or something to identify which group the node belongs to...

nevets’s picture

If by groups you mean organic groups there is a field in $node you can check (I think it is $node->groups). To be sure you can add

<pre>
<?php print print_r($node,  TRUE); ?>
</pre>

to the the top of your template file and it will show all the fields/members available in $node.

Anonymous’s picture

I do indeed mean organic groups - sorry, should have made that explicit! The node code you kindly provided gave, among other things, the following output:

 [og_groups] => Array
        (
            [0] => 38
        )

    [og_groups_names] => Array
        (
            [0] => Digital Historian
        )

So, one of my groups is called Digital Historian, and as you can see the ID of the group node is 38. How would an if statement have to look like that checks for the name of the group? I tried

<?php if ($node->og_groups=="38") { echo "38"; } ?>

but that does not seem to do the trick. Unfortunately, my PHP is very limited and as both variables return an array I am not sure how to do this...

nevets’s picture

You do not say if the node can be more than one group, in the code that follows we always use the "first" group to determine what to do

<?php
switch ( $node->og_groups[0] ) {
case 37:
   print "Group 37";
   break;

case 38:
   print "Group 38";
   break;

default:
   print "Unknown group or Not in a group";
   break;
}
?>

You would add one case per group (in the snippet is assumes there is a group 37 and 38), you will need to tailor this to your need. The default case handles nodes not in a known group (no case statement) and nodes not in any group.

Anonymous’s picture

Thank you very much, that is extremely helpful!

Yes, nodes can be in more than one group. How do you think this could best be handled from the php/code side of things? I would like it to display the logo (this is what the print statement does, it includes a logo before the heading) of the group that the node was put in first - I don't think that there would be any other easy solution. If this is to complicated it would also be OK to have all the logos there (not too many groups and the logos are smallish).

Thanks again!

nevets’s picture

I am not aware of a way to tell which group the node was placed in first. You could use something like the following to show the logo for all the groups the node belongs to.

<?php
foreach( $node->og_groups as $group ) {
switch ( $group ) {
case 37:
   print "Group 37";
   break;

case 38:
   print "Group 38";
   break;

default:
   print "Unknown group or Not in a group";
   break;
}
}
?>

From the previous example this version looks at each of the groups (the foreach loop) the node belongs to.

Anonymous’s picture

Thanks! Unfortunately, the code returns this:

warning: Invalid argument supplied for foreach()

I am not aware of a way to tell which group the node was placed in first.

There must be some way - earlier on I had different themes for different groups and Drupal automatically choose the group a node was placed in first as the group relevant for the theme, so I suspect it simple takes the first group ID it finds in the database...

nevets’s picture

Try changing

foreach( $node->og_groups as $group ) {

to

foreach( (array)$node->og_groups as $group ) {
Anonymous’s picture

Excellent!
I am really impressed by how supportive this community is!

.carey’s picture

Please let us know when you get this working, and what and how you implemented the solution so others who come across this thread will benefit as well. :)

Cheers,
Carey

Anonymous’s picture

You will find the answer in the other thread :)