Improving the theme code
In an earlier post, I outlined how I used a node-type.tlp.php file to format the output for the event content type I had created.
This is the way I've always done this kind of themeing work, since the days of drupal 4.7 [or at least I think I have]. I guess I worked it out sometime, and stuck with it. But I knew there might have been a better way. Though not outlined at the CCK themeing documentation at drupal.org, there is some fantastic documentation and code hidden in the theme folder of the CCK download. I have added this to the documentation at http://drupal.org/node/206980 The code asks you to add a small piece of code to the template.php file, and this then let's you use template files for each CCK field, as well as a default template for any CCK fields that don't have a specific template file. So I edited the node-event.tpl.php file I had created earlier. I had ripped out the $content variable, and outputted all the information manually. I removed that code and placed back the $content variable. So having followed the instructions and ammended my template.php file, I then created a field-field_lat_lon.tpl.php file with the following code <?php foreach ($items as $item) {?> Lat/Lon: <?php print $item[lat]; ?> <?php print $item[lon]; ?> <?php }?>
Simple as that.
The end result is the same, but it's much cleaner now, for a few reasons.
If I add another CCK field, it's output will still appear automatically in the $content variable, so I don't have to add it in by hand into the node-event.tpl.php file.
Secondly, If I use the lat_lon field in a few different content types, I only have to format it once.
While I was at it I also created a field-field_time.tpl.php file with the following code
<?php foreach ($items as $item) {?> "> <?php print $item[view]; ?> This also includes a cleaner way to format the ISO date that I spotted in the Zen theme.


