6
votes

How to override drupal front page node.tpl file ? I tried various

   node--front.tpl.php
   page--node--front.tpl.php
   page--front--node.tpl.php

but its not working.

What will be the file name to override home page node ? (I am working in drupal 7)

6

6 Answers

9
votes

You can add this function to theme template.php

   function customethemename_preprocess_node ( &$vars ) {

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

Then you can page page--front.tpl.php

It will solve the problem

6
votes

It should be page--front.tpl.php

Also, be sure that you have the precursors in the hierarchy for your theme (e.g. page.tpl.php)

1
votes

I would recommend solving this by setting a specific node of content to be the front page.

http://www.inmotionhosting.com/support/edu/drupal-7/homepage/change-front-page

Then I would use a specific node ID template.

node--[insert id here].tpl.php i.e. node--1.tpl.php

You need to do two things before this will work:

  1. Make sure you have a copy of the original node.tpl.php file in your theme folder (the overridden template file will not be picked up otherwise).
  2. Clear Drupal's cache
0
votes

No need to develop manually a front page, just creaate a frontpage by views or another and set it the as the front page in :

www.yoursite.com/?q=admin/config/site-information
0
votes

Following steps resolved the issue for me to create custom front page in Drupal 7.

  1. Create a file: page--front.tpl.php. Notice two hyphens instead of one.
  2. Clear the cache: Configuration >> Development >> Performance>> Clear all caches
0
votes

I think the best solution is using frontpage nid

function YOURTHEME_preprocess_node ( &$vars ) {
list(, $frontpage_nid) = explode('/', drupal_get_normal_path(variable_get('site_frontpage', 'node')));

  if ($vars['node']->nid == $frontpage_nid) {
    $vars['theme_hook_suggestions'][] = "node__frontpage";
  } 
}

Because

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

add the theme suggestion for all nodes in frontpage, not only for frontpage node