0

I would like to be able to custom theme a region for specific pages, is this possible? If so how?

For example I have a ragion called rightbar and I know the region can be themed using region--rightbar.tpl.php but is there a way of theming this using something like page--node--1--region--rightbar.tpl.php?

Or am I going to have to condition the region--rightbar.tpl.php script?

1

Use the following code:

/**
 * Implements hook_preprocess_region().
 */
function YOURTHEME_preprocess_region(&$vars) {
  // Make sure we are on a single node page
  // This code will allow you to add the following templates for regions:
  // region--node-NID.tpl.php
  // You can update the conditions to anything you want and rename the template
  // suggestions.
  if (arg(0) == 'node' && is_numeric(arg(1)) && !arg(2)) {
    $vars['theme_hook_suggestions'][] = 'region__node_' . arg(1);
  }
}
  • will this allow me to specify a specific region? – PapaSmurf Nov 6 '12 at 11:48
  • Never mind I've worked it out, thanks for this though, it was a useful guide! – PapaSmurf Nov 6 '12 at 12:25
0

I used the following code to achieve a solution to my answer.

/**
* Implements hook_preprocess_region().
*/
function care_preprocess_region(&$vars) {
    // Make sure we are on a single node page
    // This code will allow you to add the following templates for regions:
    // region--RNAME--node-NID.tpl.php
    // You can update the conditions to anything you want and rename the template
    // suggestions.
    if (arg(0) == 'node' && is_numeric(arg(1)) && !arg(2)) {
        $vars['theme_hook_suggestions'][] = 'region__' . $vars['region'] . '__node_' . arg(1);
    }
}

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.