2

The following is a simplified scenario of an organizational problem I'm facing.

I have a site with a single features module which handles all my content types. My features module is called foo and my zen subtheme is called bar.

One of my content types (e.g event) needs a special class on it so I have 2 options.

Add the class via the foo.module:

function foo_preprocess_node(&$vars) {

  if ('event'==$vars['type']) {
    $vars['classes_array'][] = "extra-class";
  }

}

or add the class via the template.php of bar theme:

function bar_preprocess_node(&$vars) {

  if ('event'==$vars['type']) {
    $vars['classes_array'][] = "extra-class";
  }

}

Which one of the two is the best location for this theme related customization? Without the feature there will be no event content type. So it feels like placing the code in the feature module file together with the content types is the best place.

On the other hand this css class is theme related so it also feels correct to place it in the template.php.

3
  • You might find that after a while your monolithic feature becomes quite large (full of these kinds of customisations) and difficult to split up (eg. if you want to use some of the content types in another site, but not all). I've personally found using a number of smaller features (eg. one per content type) to be more convenient, YMMV.
    – Andy
    Jun 28, 2012 at 10:16
  • @Andy: Interesting. I will definitely consider in a next D7 project. The question still holds though even if I only had 1 content type in the feature.
    – cherouvim
    Jun 28, 2012 at 10:38
  • oh yeah, was just digressing completely :) I agree 100% with Clive, classes are part of markup that can be targeted by CSS...
    – Andy
    Jun 28, 2012 at 12:00

1 Answer 1

2

This is just my opinion...

The HTML class itself is not related to the theme, it's related to the module defining the element on which it's placed (if it is a feature specific class name as @barraponto points out in the comments).

The styling for elements with that class is the theme's responsibility.

I would suggest that your code would be more appropriate inside the feature module. If it's not, imagine what will happen if you change themes...you'll lose the class that was on that element, meaning it can no longer be targeted for styling.

2
  • 2
    Classes aren't CSS, they're HTML. Therefore they should be meaningful. A red class shouldn't be set by the module (nor by the theme), but a signup-closed is clearly feature-specific and will benefit from being set by the feature itself. Jun 28, 2012 at 10:30
  • @barraponto Yep good point, I've changed the answer a bit
    – Clive
    Jun 28, 2012 at 20:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.