7

I'm trying to define a custom template file for a specific node, using the node ID. I read a lot of topics saying to create a node--X.tpl.php file in the templates folder.

That's what I did; unfortunately, even after flushing the theme cache many times, nothing changes.

Is there anything more I have to do?

I am using Drupal 7.

  • 2
    Have you added a copy of the standard node.tpl.php file into your theme folder as well? It's required if you want to override the node template at all – Clive Aug 13 '12 at 13:58
  • Yes I did. I already added node--content_type_name.tpl.php files in order to theme content types. My issue is just about a specific node id theme. – Ludovic Aug 13 '12 at 14:00
  • Clive's point is that you also need the basic node theme file - called node.tpl.php - in your theme folder in order for this to work. Your naming convention is correct (if you are using D7), and should work as long as node.tpl.php is there as well. – keva Aug 13 '12 at 14:14
  • Sorry my answer was not clear. Yes, I did copy the node.tpl.php file into my theme folder. I should have added that I'm using D7. – Ludovic Aug 13 '12 at 14:28
  • Do you use any base themes or something similar that overrides Drupal's defaults? I recently had a very similar situation: None of my node*.tpl.php files were fetched up by drupal after re-caching. Finally I remembered that I base on Tao theme which aggressively resets Drupal's behaviour. Also it's a good thing to ensure that at least node.tpl.php is really fetched up. – DimG Aug 14 '12 at 15:35
0

a template file page-node-{nid}.tpl.php inside your theme directory. this also work .

one thing in node-{nodeid}.tpl.php you use this.

10

In Drupal 7, node--[node-id].tpl.php is used as template file for nodes, as well as node--[node-type].tpl.php. Nothing else needs to be done, except, as Clive wrote in his comment, you also need to have node.tpl.php in the directory containing the template files used by your theme.

Notice there is a difference between node--[node-id].tpl.php, and page--node--[node-id].tpl: The latter is also used for pages at node/[node-id]/edit, or node/[node-nid]/delete. See the comment at the beginning of theme_get_suggestions().

Build a list of suggested theme hooks or body classes in order of specificity. One suggestion is made for every element of the current path, though numeric elements are not carried to subsequent suggestions. For example, for $base = 'page', http://www.example.com/node/1/edit would result in the following suggestions and body classes:

 page__node              page-node
 page__node__%           page-node-%
 page__node__1           page-node-1
 page__node__edit        page-node-edit
0

a simple method to know the good name to use for your override is drush.

Open a command line go to sites/default in your drupal and type this line :

drush vset theme_debug 1

to remove drush vset theme_debug 0..

after that reload your node and look at the code source of it. You will see all possibles drupal's propositions for everything in your page (block, region, html.tpl.php, page.tpl.php ....)

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.