How to override the first page of node tpl - drupal

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

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

but does not work.

What will be the file name for overriding the node main page? (I work in drupal 7)

+6
source share
6 answers

You can add this function to the theme template.php

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

Then you can go to the page page - front.tpl.php

This will solve the problem.

+9
source

It should be page--front.tpl.php

Also, make sure you have predecessors in the hierarchy for your theme (e.g. page.tpl.php )

+6
source

I would recommend solving this by setting specific node content on the first page.

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

Then I would use a specific node template pattern.

node--[insert id here].tpl.php ie node--1.tpl.php

You need to do two things before this works:

  • Make sure you have a copy of the source node.tpl.php file in the theme folder (the overridden template file will not be selected otherwise).
  • Clear Drupal Cache
+1
source

No need to manually design the front page, just create the front page by views or others and set it as the first page in:

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

After completing these steps, the problem was solved for creating a custom homepage in Drupal 7.

  • Create file: page - front.tpl.php. Note two hyphens instead of one.
  • Clear Cache: Configuration → Development → Performance → Clear All Caches
0
source

I think the best solution is to use 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 a theme suggestion for all nodes on the main page, and not just for the node main page

0
source

Source: https://habr.com/ru/post/924574/


All Articles