CCK for Themers

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.

Some notes on theming node-content_example.tpl.php

Benjamin Melançon - February 20, 2007 - 00:15

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

CCK themeing in Drupal 5

rainer_f - October 8, 2007 - 09:25

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

Use View not Value

jacobson - October 11, 2007 - 10:33

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

Deffinitely do not use raw data

scafmac - October 24, 2007 - 18:33

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.

How to get the custom node title on Drupal 5

Jacob - October 29, 2007 - 06:26

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

And Vice-Versa...

tommo - November 14, 2007 - 12:27

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

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

<?php
print $node->body;
?>
- as with $body

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

Tested in 5.3
Tom

 
 

Drupal is a registered trademark of Dries Buytaert.