Content Construction Kit content types can be themed in several ways. Basic instructions are in the file README.txt in the CCK module directory. The other pages in this section include some other theming tips and tricks.

Comments

mlncn’s picture

Some notes on theming node-content_example.tpl.php, as an alternative to theming individual field.tpl.php files, can be found on Agaric Design.

[UPDATE: In Drupal 5, with CCK in core, you drop the "content" and can use node-example.tpl.php. ALSO: print $node->content['body']['#value']; to get what it is in the body "field," as in Drupal 5 the regular node body is used-- but that's the precise way to get it out.]

(I'll try to clean it up and turn it into a handbook page when I'm not running a one-and-a-half night sleep deficit.)

~ben

People Who Give a Damn :: http://pwgd.org/ :: Building the infrastructure of a network for everyone
Agaric Design Collective :: http://AgaricDesign.com/ :: Open Source Web Development

benjamin, Agaric

rainer_f’s picture

In Drupal 5 with CCK module installed and activated, you just define your content type, then create a node-contenttype.tpl.php file to render the nodes for that content (replace "contenttype" in the filename by the "machine readable" content type name you gave while creating the type).
To access your customized fields within the template using $fieldname[0][value] where fieldname is the "machine readable" fielde name you provided while creating the field.
Note: Don't use the $content variable in your tpl.php file, it contains the default CCK rendering you wont need.

That's all.

Rainer
Professional Drupal services for Germany
http://www.feike.biz

jacobson’s picture

In studying use of CCK fields in themes, I have read that a template should refer to $fieldname[0][view] not $fieldname[0][value]. The 'value' is the raw data, and the 'view' is the data prepared for presentation by Drupal and CCK. I'm not sure exactly of the differences.

HAJ

scafmac’s picture

I believe the difference is what the raw data has not been processed by the input filters. Drupal has a policy of not removing offending content (unsanctioned html or external references), but just filtering it before displaying it. The value has the raw data and the view has the filtered version.

Jacob’s picture

Thanks, Benjamin, the way to get the custom node body is $node->content['body']['#value']; indeed.
I'd like to save time to some of you, guys, trying to figure out how to get the second predefined custom node field - title.
So,

<?php print $title;?> - works
<?php print $node->title;?> - works
<?php print $node->content['title']['#value']; ?> - does not works

Hmm, $node->content['title']['#value'] does not work, while $node->content['body']['#value'] does....

Jacob.
P.S. tested on Drupal 5.3

tommo’s picture

I have come accross this same problem Jacob but the other way around:

print $node->content['body']['#value']; - works
print $body; - gives you everything within the node - i.e. is the same as print $content
print $node->body; - as with $body

And I thought my tpl file wasn't even working!

Tested in 5.3
Tom

TimG1’s picture

Hi guys,

So, I'm using print $node->content['body']['#value'] and it works great for my purposes.

However, when I click on the edit tab and then scroll to the bottom and click on the Delete button to delete a page, I get the confirmation message "Are you sure you want to delete _page_title_". But, there is no Delete and Cancel button to confirm the delete.

It shows up when I use print $content .

Any help is appreciated! Thanks!
-Tim

bethhauck’s picture

I have this problem too. My guess is that it's just because the delete button is not located in the body section of the content - there must be another section to add to the template. Does anyone know what's missing?

gumdrop’s picture

Does this:


  <?php if ($node_bottom && !$teaser): ?>
    <div id="node-bottom">
        <?php print $node_bottom; ?>
          </div>
            <?php endif; ?>

bethhauck’s picture

Thanks for the suggestion, unfortunately it doesn't seem to have any effect in my case.

Can anyone tell me what the pieces that make up $content are called, and/or where I would look for a complete list of them?

davidwhthomas’s picture

Pass the function the node object and it'll return the cck fields in a table.
The function sits in template.php

<?php
/**
 * return cck fields formatted as table
 * @param $node full node object
 * @return string HTML table
 */
function phptemplate_get_cck_table($node){
  // get fields
  $fields = content_fields(NULL, $node->type);
  $header = array('', '');
  $rows = array();
  // loop through and check if field is set in node
  foreach($fields as $fieldname => $field){
    $row = array();
    if(! empty($node->{$fieldname}[0]['value'])){
      // make row of label and value
      $row[] = array('data'=>$field['widget']['label'], 'class'=>'field-label');
      // handle multiple values
      foreach($node->{$fieldname} as $key => $value){
        if(isset($node->{$fieldname}[$key]['view'])){
          $row[] = array('data'=>$node->{$fieldname}[$key]['view'], 'class'=>'field-item');
        }else{
          $row[] = array('data'=>content_format($fieldname, $node->{$fieldname}[$key]), 'class'=>'field-item');
        }
      }
      $rows[] = $row;
    }
  }
  return theme('table', $header, $rows, array('class'=>'cck-table'));
  //var_dump($fields);
}
?>

You can call it from node.tpl.php like

<?php
print phptemplate_get_cck_table($node);
?>

DT