I'm having trouble getting my theme to override node-og-group.tpl.php - is there something special that I need to be doing other than placing a node-og-group.tpl.php file in my theme's directory? (no other OG modules installed)

CommentFileSizeAuthor
#4 og-readme-txt.patch1.81 KBmarcp

Comments

marcp’s picture

After you copy node-og-group.tpl.php to your theme's directory you'll need to rename it to reflect your group's node type(s). If your group node type is "club" then you'd rename node-og-group.tpl.php to node-club.tpl.php.

One or two additional lines in README.txt would probably keep this question from showing up so often. Lines 34 thru 38 in README.txt would be the place for the change(s) -- if you come up with some wording, I suspect you can get it in there and save some other folks the hassle of figuring this out for themselves.

moshe weitzman’s picture

Status: Active » Fixed

@marcp - thats inaccurate. All thats needed is to copy node-og-group.tpl.php to your theme dir and then hack away as desired. It will apply for all group node types. You only need to rename it if you want your changes to apply to a single content type. Of course, anytime you do a theme override like this you must clear the theme cache. see bottom of admin/settings/performance.

the theme developer module (see devel package) is a good way to see what possible theme file names will be accepted and thus understand what your best override strategy is.

marcp’s picture

That shows how much I know! Thanks for the correction, Moshe.

marcp’s picture

Status: Fixed » Needs review
StatusFileSize
new1.81 KB

I probably should just leave this alone, but a README.txt patch is attached.

elgreg’s picture

Moshe's solution is the one that I'd like to use (as I have three different types of groups and I'd like them all to have the same layout). I copied node-og-group.tpl.php to my theme directory, but to no avail, it's still going after the one in the module directory. If I remove the one in the module directory, then it picks up the one in my theme directory (I wouldn't actually do this, of course, as it blows the upgrade path). Does this mean that I need to register the file or something? I see the lines in og.module that registers the node-og-group file...
(l320)

  elseif (og_is_group_type($node->type)) {
    // This looks awful on a group node
    unset($variables['submitted']);
    array_unshift($variables['template_files'], 'node-og-group');
  }
}

and

(l327)

function og_theme_registry_alter(&$variables) {
  $variables['node']['theme paths'][] = drupal_get_path('module', 'og');
}

wondering if need to do something similar to get mine to pick up. And, yes. I've cleared the cache like a champ. :)

--UPDATE: I added this code to a custom module and a corresponding template file (node-my-groups-template.tpl.php) it picks that up (after emptying the cache, of course).

function my_groups_preprocess_node(&$variables) {
	$node = $variables['node'];
	if (og_is_group_type($node->type)) {
    array_unshift($variables['template_files'], 'node-my-groups-template');
  }
}

I thought that the non-override might be because I'm using a sub-theme, but even when I dropped node-og-group.tpl.php into Garland and emptied the cache it wasn't picked up. ??

moshe weitzman’s picture

Status: Needs review » Fixed

I found a bug in the way that I injected theme_paths. This made it very hard to override og provided templates fro mwithin the theme. We should be good now. Please reopen if needed.

elgreg’s picture

Cool! I took a look myself and changed the line in og.module from

function og_theme_registry_alter(&$variables) {
  $variables['node']['theme paths'][] = drupal_get_path('module', 'og');
}

to:

function og_theme_registry_alter(&$variables) {
  array_unshift($variables['node']['theme paths'],drupal_get_path('module', 'og'));
}

to push the path on the top beginning of the end of the array and it looks like this took care of allowing node-og-group.tpl.php file to override in my theme.

Is this about the same as what you did in your patch?

Thanks for the quick attention!

moshe weitzman’s picture

close. see http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/og/og.modul.... the og path has to come just before the modules/node

elgreg’s picture

Touché! :)

mshaver’s picture

This works fine now. If you wanted to use the default node.tpl.php file instead of the node-og-group-post.tpl.php, how would you do so?

moshe weitzman’s picture

the easiest if to move/delete the og one. if you want to leve it, you have to unalter what og does in its theme_register_alter hook.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

noelbush’s picture

Category: support » bug
Status: Closed (fixed) » Active

I am using 6.x-2.0-rc3 and I have this same problem. I have copied node-og-group-post.tpl.php into my theme's directory and made my desired modifications. I have rebuilt the theme registry. Yet my template file is still not picked up, according to the Theme Developer UI. It shows the original og version still being used. Is this a regression, or is there something else I should check?

mshaver’s picture

I threw this bit of code into my template file within the preprocess_node function so that I could use the standard node.tpl.php file instead of the node-og-group-post.tpl.php. Not sure if that helps you though?

  // Stick with node.tpl.php, not node-og-group-post
  $key = array_search('node-og-group-post', $vars['template_files']);
  if ($key !== FALSE) {
    $vars['template_files'][$key] = NULL;
  }
moshe weitzman’s picture

Status: Active » Postponed (maintainer needs more info)

Works for me. Your theme (or subtheme) has to implement node.tpl.php as well. Thats a limitation of core drupal..

iamwhoiam’s picture

Fantastic, thanks. The latest dev fixed it.

ajayg’s picture

@moshe
just want to bring to your attention about comment #8
in the 6.x.1-3 version that line is

array_splice($variables['node']['theme paths'], 1, 0, drupal_get_path('module', 'og'). '/theme');

Vs the latest in Dev is

array_splice($variables['node']['theme paths'], 1, 0, drupal_get_path('module', 'og')); 

Notice the "/theme" missing in the end in latest dev. IS that what you intended since there is a theme directory inside og module. Or that directory is more of documentation purpose and the theme inside those directoy, if kept as it is, has no effect till copied to your sites theme directoy?

moshe weitzman’s picture

Status: Postponed (maintainer needs more info) » Fixed

that looks like a bug in 6.x.1 series but is fixed in 6.2 which is releasing very soon.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

francis55’s picture

Status: Active » Closed (fixed)

Hi all,

I am trying to change the layout of the group's main page.
I have overridden all the following files in my theme:

  • node.tpl.php
  • node-group.tpl.php
  • node-og-group.tpl.php
  • node-og-group-post.tpl.php

then cleared the cache
I've seen the change on an ordinary page, but the pages within the group - particularly, the group page - remain unchanged.
I am using Drupal Commons: Drupal 6.22, Drupal Commons 1.7
The cascade of themes, as far as I can gather, is:
my theme > Commons origins > Commons roots > fusion_core

francis55’s picture

Status: Closed (fixed) » Active
Grayside’s picture

Version: 6.x-1.0-rc4 » 6.x-2.1
Status: Closed (fixed) » Active

Don't know what could be causing that, the code has been working fine for years now. I imagine commons is on 6.x-2.1 now.

However, I suspect this relates to how you are building out the theme. I suggest you pursue theme-oriented support channels, and if expected behavior is not working, return here.

Grayside’s picture

Status: Active » Postponed (maintainer needs more info)

  • moshe weitzman committed 50caa6a on 8.x-1.x
    #287298 Fix the theme registry such that it becomes possible to override...
claudiu.cristea’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.