Last updated December 11, 2014. Created on February 19, 2005.
Edited by satvision83, Manjit.Singh, davidneedham, goron. Log in to edit this page.

Note: To do this in Drupal 7 please see Drupal 7 Template Suggestions.

The file node.tpl.php is used to theme certain types of nodes. This single file generically covers all Content Types and you can edit it to make changes across the board as detailed on the node.tpl.php handbook page. To theme individual content types in different ways, you need to create a file node-[type].tpl.php in your theme's folder, where [type] is the machine readable name of the content type, for each type you wish to theme. Some examples:

For Drupal 7

Themes only Story type nodes.
Themes only Page type nodes. Note that this is different from page.tpl.php which controls the layout of the entire page including header, sidebars and so on.
Themes only Forum type nodes.
Themes only Book type nodes.

For Drupal 6

Themes only Story type nodes.
Themes only Page type nodes. Note that this is different from page.tpl.php which controls the layout of the entire page including header, sidebars and so on.
Themes only Forum type nodes.
Themes only Book type nodes.

In Drupal 7, we use two hyphens, so if the content type is let's say "news", the node template will be node--news.tpl.php.

In general, you can replace [type] with any content type system name. One exception is the Flexinode module, which uses numbers to name the types. See Node Templates for Flexinode Content Types. Note that you cannot use node-admin.tpl.php to theme just the admin pages—but you can use page-admin.tpl.php to theme the admin "pages".

Once you have this new file, copy in the contents of node.tpl.php and modify it however you wish. All the variables listed on node.tpl.php can be used.

NOTE: When using phptemplate node-[type].tpl.php suggestions, there must also be an original node.tpl.php template present in your theme directory or the template suggestion is ignored.

This is also the case for subthemes. Just copy the parent themes node.tpl.php into your subtheme folder and refresh the theme cache.

More details can be found at the Core templates and suggestions handbook page.

Drupal 6

For more information on theming nodes by content type in Drupal 6, please refer to the following handbook pages:

Looking for support? Visit the forums, or join #drupal-support in IRC.


jindustry’s picture

This technique seems to work for D6 despite only listing "Drupal version: Drupal 4.6.x, Drupal 4.7.x, Drupal 5.x".

sirspacey’s picture

In Drupal 7 use two hyphens.

Themes only Article type nodes.

Themes only Page type nodes. Note that this is different from page.tpl.php which controls the layout of the entire page including header, sidebars and so on.

Themes only Forum type nodes.

bsacks’s picture

Wish I had scrolled down and read this earlier. Two hyphens! Is this a bug that's going to get fixed and then break my template?

goron’s picture

Here's the page with full details on D7 tpl files:

Stan.Ezersky’s picture

I have node type with machine name _some_thing

What is the name of template?

Yikai Wang’s picture

Oh, thank God finally find the problem! thank you thank you!

gkmbinh’s picture

Dear, please give a template full demo for custom content type.

J. Daglees’s picture

technotarek’s picture

Let's say I've created a content type called "my_content_type". I understand that you could template/theme that entire content-type by creating "page-node-my_content_type.tpl.php". But, what would be the best way to then further customize a single node of that content type (e.g., node 5555)?

I tried the following, but none worked:


None of these work. They all continue to use my original content-type template.

Kakoma’s picture

You could use
node--5555.tpl.php (two hyphens for Drupal 7)

alibama’s picture

hi = what if i need to style the node/add or node edit pages? i've tried node-edit-[content-type] and node-add-[content-type] as well as node-[content-type]-add node-[content-type]-edit to no avail.. any pointers welcome

Syd Barrett’s picture

You can try this

function YOURTHEME-NAME_preprocess_page(&$vars, $hook) {
  if ((arg(0) == 'node') && (arg(1) == 'add' && arg(2) == 'CONTENT-TYPE')) {
    $vars['template_files'][] =  'page-node-add-CONTENT-TYPE';
polluxmr2’s picture

I have a question about the specific search pattern drupal 7 uses.

Lets say i have content type "test", "my content type" and "test-test" with machine names of "test", "my_content_type_" and "test_test" respectively. Would the theme file name for each (assuming i wanted to theme by content type) be:


or are underscores replaced with a hyphon?

platypusjones’s picture

If the machine name of the content type contains underscores you translate them to a hyphen.


should be:

No need for the trailing hypen or underscore either,




cocoonfx’s picture


I am pretty new to DP7 7.14. I have setup a content type called Services with the machine name as services. I want the services page(s) to have a different style than the rest of the site.

I have added the following to the template.php file.

function template_name_preprocess_page(&$vars) {
	// Add per content type pages
	if (isset($vars['node']->type)) {
	  // Add template naming suggestion. It should alway use hyphens.
	  // If node type is "custom_news", it will pickup "page-custom-news.tpl.php".


I then created a page--service.tpl.php how the services page doesn't work. I am not sure why its not working.

Can anyone suggest why this couldn't be working?

jpbeaulieu’s picture

You must write two underscores instead of one.

function template_name_preprocess_page(&$vars) {
    if (isset($vars['node']->type)) {

Now, page--service.tpl.php will work.

Elehas’s picture

I had to use template suggestions in my template.php file. When I did node-[type].tpl.php, it would read that template inside of my entire page.tpl.php template. If you need the system to JUST read the template you're creating for specific content types, try this:

function THEME_NAME_preprocess_page(&$variables) {
   if ($variables['node']->type != "") {
      $variables['template_files'][] = "page-node-" . $variables['node']->type;

This worked great for me.

taggartj’s picture

just wondering about Drupal 8 as trying to theme a custom content type , as there is no documentation on this yet I was first a little shocked that d7 "page.tpl.php" themes files will now be "page.html.twig", which is the scarey brain child of people who brought you the Symfony frame work :(

lets hope the gods Decide the template files can be in ether good old fashion tpl.php as well as for the people who want to mess with .twig ... as I don't see any thing wrong with old fashion php ... except a small (minimal) performance gain.

Any way trying to make a custom template file for the node.html.twig

content type: = test
I have tried :

node-test.html.twig, node--test.html.twig, node-test-content-type.html.twig , node--test-content-type.html.twig , node-test.html.twig , and many more :

sure i can change the node.html.twig to do what i want , but i want to know how to do it like drupal 5, 6, 7 does it.

just so when d-day comes and we all then need to update / upgrade many complex d7 sites to new drupal 8 - we can have a leg up and prepare for the unnecessary.

technopteam’s picture

There is a work around for D8. You can see the hint in this post :

In YOURTHEME.theme file add the following hook to let twig know about your custom templates suggestion when rendering page.html.twig :

function YOURTHEME_suggestions_page_alter(&$suggestions, $variables) {
  // Get current node
  $node = \Drupal::request()->attributes->get('node');
  if ($node) {
    // Node type project && page template
    if ($node->getType()) {
      $suggestions[] = 'page__' . 'node__type' . '_' . $node->getType();

And in debug mode, you should see a new suggestion page--node--type-article.html.twig for example.
It works for D8 8.0.0-beta9.

I agree, it would be great to have the node type already injected in the $variables param.

Best Regards,

david_capptiva’s picture

Is it possible to move the node-[type].tpl.php to a module folder instead that having it in the theme folder?

I have a module that creates a custom content type and I want to provide a default template to drupal_render.

Thanks all.


Piulres’s picture

How do I set a node.tpl for each different type of content type?
I am new in drupal and new in this forum. If I have not asked the right questions in the right places, please report to me.

caiman’s picture

If the solution doesen't work for you, please check again that your cache is empty (Administration > Configuration > Development > Performance > Clear all caches).

W.M.’s picture

[D7] Where to put the custom node--page.tpl.php file for a core theme i.e. garland? I prefer to put it outside core directory in order to avoid loosing it on updates. Any ideas? Thanks.