I'm working on a website where the designer came up with 5 theme colours which I need to associate with specific pages. The theme has 2 regions which need to be affected by the theme colour: sidebar and content. I was hoping to add a field to the Basic Page content type linked to taxonomy vocabulary where the terms would be the colours so I could pick the theme while creating the page. I would need to add a class with the term somewhere height enough to affect all other fields of Page content type. This would be something like row classes in Views where I can use Replacement patterns to call on fields from this node.

The most difficult option would be to be able to affect the content and the sidebar (the object with that class="term/colour" would have to wrap both of the regions) but if anybody knows how to add it to only the content region, that would be great too.

At the moment, I put all the theme rules into the CSS based on node classed in the body tag, but I'm not particularly proud of this solution.

It might be worth adding what themes I use. For the desktop site, I used Omega 4 and for the mobile site, it's Bootstrap3. I'm in the middle of transitioning to Bootstrap.

Any help would be greatly appreciated.


(spaghetti code alert!)
It's not the best and perfect way, but you can take advantage of TEMPLACE_preprocess_html hook to add a class to body tag.

I used Bootstrap sub-theme. Snippet at follow it's quite simple, before process the page I check if it's a News content type, if so i add a custom class at body tags. Field_school it's a term reference.

file: template.php
  * Implements TEMPLATE_preprocess_html().
function TEMPLATE_preprocess_html(&$variables) {
  $node = menu_get_object();    

    // News content type
  if ($node && $node->nid && $node->type === 'news') {
    $schools = $node->field_school['und'];      
    foreach ($schools as $school) {         
        $variables['body_attributes_array']['class'][] = strtolower('school-' . $school['taxonomy_term']->name);

This is the link where I got this info: link

I hope to have been helpful.

| improve this answer | |

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.