Recently I had to override the Drupal node.tpl.php file in Drupal 7 with a custom one. I went to some issues so I thought I would post this here and share how I overcame my obstacles.

Steps to Follow

1) Copy the node.tpl.php in your theme.
2)Rename it node--"yourContentTypeMachineName".tpl.php
for example my custom file is now node--image_archive.tpl.php
3) to test it out write some text(anything) in your new node.tpl file.
4)paste your new node.tpl file back in you theme folder
5)Clear all cache
if you go back to the content node on your dupal site you should see the text you wrote in the file

Pitfalls

1)For Drupal 7 you need the 2 dashes -- when renaming the file
2)the node name must match the content type machine name exactly
3) you mush clear all cache

Comment as you see fit

Thanks

Comments

avalentini’s picture

I'm having difficulties with the whole node file. What should I check?

ashutosh_anand’s picture

If you are using Drupal 7,
1. Create a basic page (For example it is node/20)
2. Copy node.tpl.php to node--20.tpl.php
3. Now modify node--20.tpl.php and add some text
4. Clear your Drupal installation's cache. (Path: admin/config/development/performance)
5. Refresh node/20 or the node which you created on step 2 and for which you overrode node.tpl.php at step 2.
6. Changes done on node--20.tpl.php should reflect on content with path node/20

anber500’s picture

Thanks. This helped a complete Neophyte.

tomarnold2’s picture

I'm also a newbie at this. I appreciate the clear steps above. I don't know if it applies to the node.tpl.php, but for views I know that the underscore must be changed to a dash. So, if your machine name is "toms_cool_view" and I'm trying to override the views-view.tpl.php, the override would be views-view--toms-cool-view.tpl.php (note the double-dash as described above, and then '_' converts to '-'). Regardless, thank you so so much for the help. It's easy once it's understood, but dang, the path to figuring it out can take some time. :D

rgenck’s picture

I've done this before, I just can't find node.tpl.php for the life of me! Where do I find it in the file structure of any given server? page.tpl.php is typically under public_html -> modules -> system, so where do I find the node file to override?

tomarnold2’s picture

I have found that going into my local settings.php file and, at the end of the file, adding this setting, it's been hugely helpful:
$conf['theme_debug'] = TRUE;
--
Then restart your server, etc.

Then, go to the page you want to find the .tpl.php for and view the source of the page. There, in that page, you will see comments added that are the clues you seek for what pages are available to you for overriding. For example:
<- THEME DEBUG ->
<- CALL: theme('html') ->
<- FILE NAME SUGGESTIONS:
* html--node--110964.tpl.php
* html--node--%.tpl.php
* html--node.tpl.php
x html.tpl.php
->
--
the 'x' marks which one is being used and the '*' shows which ones it will take as an override.

The files should be placed in the /sites/all/themes//

I don't know that this answers your question, but hopefully it points you down the right trailhead.

Tom

P.S. Continue to scroll through your page's source and you'll continue to find clues. Continuing with my example from above, I eventually find:

<- THEME DEBUG -->
<- CALL: theme('page') -->
<- FILE NAME SUGGESTIONS:
* page--node--110964.tpl.php
* page--node--%.tpl.php
* page--node.tpl.php
x page.tpl.php
->

...and...

<- THEME DEBUG ->
<- CALL: theme('node') ->
<- FILE NAME SUGGESTIONS:
* node--110964.tpl.php
* node--page.tpl.php
x node.tpl.php
->
<- BEGIN OUTPUT from 'sites/all/themes/omega/omega/templates/node.tpl.php' ->
...and so on. (Note the node.tpl.php in the line just above) I would try placing it into my themes directory and see if it gets picked-up.

(had to edit this because the comment HTML ended up being commented out of my response.) :-D