Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a node.tpl.php file that is only used by the front page in Drupal 7

I created a page--front.tpl.php successfully.

Is there a similar way to create an instance of node.tpl.php that only gets called by the front page?

That would leave the main node.tpl.php untouched to be used in the rest of the site and content.

like image 895
Charlie Avatar asked Dec 17 '22 13:12

Charlie


1 Answers

I believe you are looking for something like the below. This uses the template_preprocess_node function, and this code belongs in your active theme's template.php file:

function YOURTHEME_preprocess_node ( &$vars ) {
    if ($vars["is_front"]) {
        $vars["theme_hook_suggestions"][] = "node__front";
    }
}

and then create your template file named node--front.tpl.php, empty your site cache, and now you should have a template file for nodes specifically displayed on the front page, while your original node.tpl.php will be used everywhere else.

like image 144
NJH Avatar answered May 12 '23 05:05

NJH