Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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

2 Answers 2

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:

forum
forum/*

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

if($sidebar):

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

share|improve this answer

Your Answer

 
discard

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.