2

I've been reading through a ton of Drupal 7 theming docs but can't seem to find my answer.

Here's what I'm trying to do. I have two content types article and feature.

Nodes of both content types are displayed on my /blog page via the Views module. All working great so far.

When the node of type article is listed, it uses the node--article.tpl.php template, and when a node of type feature is listed on the blog listing page, is uses node--feature.tpl.php.

This is all as expected, BUT for feature types, I want to display the node--article.tpl.php template only on the /blog page, and use node--feature.tpl.php (the default) for that type otherwise.

In other words, I'd like to keep the templates separate, but use the same template for both article and feature types on the blog listing page (node--article.tpl.php).

Is there way to create a node-page-specific template file (use this template for this node ONLY if on this page)?

8

add template.php:

function THEMENAME_preprocess_node(&$vars) {
  if (request_path() == 'specific/page') {
    $vars['theme_hook_suggestions'][] = 'node__specific';
  }
}

and create file node--specific.tpl.php in theme dir

0

If you're using views why not just switch to field display rather than node display? You could probably then just copy your node--article.tpl.php to the right views tpl and it would just pick it up.

0

While considered evil in certain circles, you could certainly put something like:

<?php

$foo=explode('/',$_GET['q']);

if ($foo[0]=='blog') {

    ALL YOUR BLOG SPECIFIC TEMPLATE PHP GOES HERE

} else {

    TEMPLATE PHP FOR EVERYWHERE ELSE GOES HERE

}

in your node template file.

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.