Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I’m trying to modify my theme’s page.tpl.php to not show certain regions when I’m displaying content from the core forum module.

<?php if (!$node->type == 'forum'): ?>
<div id="sidebar"><?php print $sidebar; ?></div>
<?php endif; ?>

This works fine when I display actual forum nodes, but not when I show pages with the forum listings (/forum, /forum/1, etc.), since those pages aren't actually nodes.

How can I determine if a page will be a certain content type, so I can use conditional statements in page.tpl.php?

Edit: Some quick clarification. Working with $node->type is easy for pages that actually use nodes. However, when working with Views, or in the case of the forum module, the content is not node-based (it is called with forum-topic-list.tpl.php and $node is null). Because of this, it's impossible to programmatically determine if the page is really a forum (since it's not really a node). I'm trying to figure out a way around that.

Edit 2: Possible (kludgy?) solution: Putting this in theme_preprocess_page works. Is it the best way to do it though?

// Determine if page is a forum
$node = $vars['node'];
$template = $vars['template_files'][0];

if ($template == 'page-forum' || $node->type == 'forum') {
    $vars['is_forum'] = TRUE;
share|improve this question
up vote 2 down vote accepted

Use template_preprocess() for detecting node on page and pass additional variable as flag to template file, like:

$variables['display_region'] = TRUE;

Maybe Panels can help you too.

share|improve this answer
That doesn't quite solve the problem. Not all pages are nodes, especially when working with views or the forum module. Pages that display the forum details call forum-topic-list.tpl.php and don't act as nodes—$node-type is null on those pages. – Andrew Jul 16 '11 at 21:43

Pages do not have a content type, only nodes do. You're trying to do something programmatically here that is actually very easy to accomplish via the Drupal UI.

I would suggest that instead of hiding the sidebar region on non-forum pages in the page template, simply set the sidebar blocks' visibility to be shown only on forum pages:


Then you only need a simple check to see if there is sidebar content in your page template


More information on Block Visibility settings here: http://drupal.org/node/21870

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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