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.
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
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 usenode-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
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
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
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
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 worksHmm, $node->content['title']['#value'] does not work, while $node->content['body']['#value'] does....
Jacob.
P.S. tested on Drupal 5.3
And Vice-Versa...
I have come accross this same problem Jacob but the other way around:
<?phpprint $node->content['body']['#value'];
?>
<?phpprint $body;
?>
<?phpprint $content
?>
<?phpprint $node->body;
?>
And I thought my tpl file wasn't even working!
Tested in 5.3
Tom