Last updated April 30, 2007. Created on May 8, 2006.
Edited by Dublin Drupaller, add1sun, ac, KarenS. Log in to edit this page.

Copy the code below (taken from a typical node.tpl.php file) into a text editor and save it into your theme's folder. The name of the file depends on your version of CCK. For 4.7 use node-content_example.tpl.php (substituting the name of your content type for 'content_example') and for 5.x use node-example.tpl.php (again, replacing 'example' with your content type's name).

<div class="node<?php if ($sticky) { print " sticky"; } ?><?php if (!$status) { print " node-unpublished"; } ?>">
    <?php if ($picture) {
      print
$picture;
    }
?>

    <?php if ($page == 0) { ?><h2 class="title"><a href="<?php print $node_url?>"><?php print $title?></a></h2><?php }; ?>
    <span class="submitted"><?php print $submitted?></span>
    <span class="taxonomy"><?php print $terms?></span>
    <div class="content">

      HERE IS WHERE YOUR CONTENT WILL GO

    </div>
    <?php if ($links) { ?><div class="links">&raquo; <?php print $links?></div><?php }; ?>
  </div>

Now navigate to a node using that content type, something like:

http: //www.example.com/node/27

You will see the page headers, links, etc., but will just see the message 'HERE IS WHERE YOUR CONTENT WILL GO' where the content should be because you haven't put anything in there yet.

There are a lot of ways to fill in the content. The simplest and most basic is to just output the node's default content, using the following code:

...
<div class="content">
  <?php echo $body ?>
</div>
...

This will give you a node that has all the default formatting. If you like that presentation, your template is done and you're ready to go.

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

Comments

chillpenguin’s picture

...
<div class="content">
  <?php echo $body ?>
</div>
...

^^ I don't believe that is correct. Using this causes no content to appear.

...
<div class="content">
  <?php echo $content ?>
</div>
...

^^ This one works though.

oxcoda’s picture

I found the following to be the best way to get the original body out:
<?php echo $node->body; ?>
Otherwise you also get the content with the custom fields added.

The above can be used for any custom (CCK) field, eg:
<?php echo $node->field_first_name; ?>

Note: I am using the dev version on Drupal 6.

estim8d’s picture

I'm using 6.2 - does this still work?

<?php
 
echo $node->field_first_name;
?>

I just get after selecting a field, "array" in text...

oops - just read the next page - use this instead:

<?php
 
print content_format('field_projectsummary', $field_projectsummary[0]);
?>
dynlist’s picture

I'm using Drupal 6.14, and Content Profile (6.x-1.0-beta4) to build the profile page. The name of the content type I created is "Application". By using Devel, the Candidate template file is "page-user-profile-application.tpl.php". Does it mean I should take file from a typical page.tpl.php, or node.tpl.php still, when I copy the code?

Basically, I'm new to Drupal coding. The thing I need to do is to access each field in the profile page, so I can control their appearance, like to hide the "Name" field, to change the layout of a group of checkboxes. "page-user-profile-application.tpl.php" seems work for me, as it has been loaded by Drupal, and

<?php
 
print $content
?>

works. However, each individual field is still not accessable.

<?php
 
print content_format('field_first_name', $field_first_name[0]);
?>

shows nothing.

Please help.

unikum’s picture

I am not sure what would you like to theme. If you want to make new theme for whole HTML document, use the page file. If you want to theme just the part of HTML document where is content, use node file.

I think you want to theme just the node file, so you should make node-application.tpl.php and take file from node.tpl.php. You can print individual field (first_name) like this:

<?php
print $node->field_first_name[0]['safe'];
?>

I hope this helps.

afaaro’s picture

What is the best way to print multi value, with this [

<?php
 
print $node->field_features[0]['view']
?>

] It just shows 1 value.

afaaro’s picture

Thank you, I have done it through this:

<?php
 
foreach ($field_phone as $phone) {
?>
<?php
 
print content_format('field_phone', $phone)
?>
<?php
 
}
?>