CCK & Views the ultimate combination – part 3

Drupal is a fantastic content management system but is perhaps not the most non developer friendly however 3 simple modules can help you create compelling and powerful web site. So in this 3 part mini series lets see how easy it is to develop new content types and ways to view it. To help us lets use a fictitious company called AA Design who are about to start teaching a range of courses.

Quick note this post refers to Drupal 4.7 however several of these modules are now available for Drupal 5

Themeing our CCK and Views

Ok so in part 1 we looked at how CCK (Content Construction Kit) can be used to develop new nodes, while in the second part we discussed views for displaying your custom content along with other nodes. You may have noticed that the results of your custom content was a bit ugly so we are now going to make it pretty by using two modules Contemplate and Panels.

Contemplate

The Content Template (a.k.a. ConTemplate) module allows modification of
Drupal’s teaser and body fields using administrator defined templates.
These templates use PHP code and all of the node object variables are
available for use in the template.

Contemplate simply allows you to theme a custom node built with the CCK without resorting to messing up your template.php file to much. To get started we will need a custom node built with CCK see part 1 for details and the contemplate module which is installed in the now very familiar way. Once installed we can theme our template by going administer -> content -> templates this brings up a list of all the node types with an option to create template, for non custom modes it is easier to carry out themeing changes in the normal way but create a template for our custom node type. If you followed our first article we created a node for courses, one of the fields was cost, which we defined as a number rather then text, this may have seemed odd as you could not work out if it was a price, lets theme this field. When you clicked create template you are presented with 2 templates one of the teaser and the other the full node view of the node, a quick look through the code should explain how to edit the nodes


<div class="field field-type-text field-field-brief-description">
  <h3 class="field-label">Brief Description</h3>
  <div class="field-items">
    
      <div class="field-item"></div>
    
  </div>

The sample here shows a typical CCK field, your template will have repeated variants of this for every field created it does not take much to work out what you can and can’t edit and you can change the class in div or any tag to one in your style sheets or create new ones. Lets quickly edit our course price.


<div class="field field-type-number-integer field-field-cost">
  <h3 class="field-label">Cost</h3>
  <div class="field-items">
    <?php foreach ((array)$field_cost as $item) { ?>
      <div class="field-item">£<?php print $item['view'] ?> Per Person</div>
    <?php } ?>
  </div>
</div>

This is a really simple alteration but hopefully lets you relise you can pretty much treat this like any other template. This module works particularly well with the Jscript module

Panels

This module allows you to create pages that are divided into areas of the page. Where the dashboard module only gave four areas–top, bottom, left and right–this one is a completely flexible system that includes a couple of 2 column and 3 column layouts by default, but is also highly extensible and other layouts can be plugged in with a little HTML and CSS knowledge, with just enough PHP knowledge to be able to edit an include file without breaking it.

Panels is a great module for giving you a more flexible layouts, I will discuss the more advance layout bits in a later tutorial so for now we will use its default templates. Download and install the Panels module as per normal, then administer->Panels we are going to create a new panel, so click add. From the Layout page choose the two column layout, you will then be presented with a page that allows you to add content to your page, add a title, CSS ID (this is so you can reference the panel div’s for further themeing) and a URL, you do need to specify a URL even if you have Pathauto module installed. The next step is to add content, this is done using the add content field set, simply select the column you wish to add content to then choose, either a Block, Views or node number/title and click the add button next to it, you can also add a custom title to the column using the custom title field. Finally click save and then view your two column page. When using panel and views I find it easier to use blocks linking to full views unless I’m displaying a small amount of data, this for me is easier to work with but has the disadvantage that you can not use pagers in blocks.

Conclusion

These three tutorials have really just meant to be introductions into Drupal modules, a lot of people think that without good coding skills they will be unable to create complex sites, hopefully these tutorials have changed those people minds, we would love to hear your feed back and any problems with the tutorials if you don’t want to leave a public comment you can always email me at t.nash at venture-skills.co.uk. In future Drupal posts we will look at more advanced features of the modules we have described here. In the mean time you can always check out our other Drupal posts including our series "Want to create a site like Digg with no programming"

Other articles in the series
CCK & Views the ultimate combination -part 1
CCK & Views the ultimate combination – part2
HReview a CCK example using contemplate

Get our Content via RSS feed using Feedburner
Other Articles on the Venture Skills Network about Drupal
Drupal 5.0 goes Beta
5 Drupal Modules to Guarantee Drupal 5.0 Success
The Digg effect and can drupal survive it
– looking at how Drupal can cope with bandwidth spikes
Want to create a site like Digg with no programming part 2

Like what you see try these articles on the Venture Skills Network
What’s the future for Google Hosted Applications – Is the future Bright?
Information mining the social way – Using del.icio.us to mine your competitors
Skype vs the World - Is Skype scalable?

Subscribe to The Venture Skills Blog by Email

PodcastAll our Posts are audio subscribed for more information see here, and to access the podcast feed here

Posted in Technology, drupal, links. Tags: . 5 Comments »

5 Responses to “CCK & Views the ultimate combination – part 3”

  1. Emma Rush Says:

    Your tutorials were extremely helpful, although I’m still not entirely sure what a view is or does. Drupal is so massive it makes my brain hurt.
    One suggestion, however. Your long sentences make comprehension a little difficult….but hey! It was a great tut and thanks for taking the time to write it.

  2. Venture Skills Team Says:

    think of a view as a list, so it could be a list of eggs, or tomotatos. In this case its a list of nodes, now like any list, you can write a description next to the item (so it would be a list with teasers) you could collect a group the things together and put them on the list (full nodes) or individual parts (fields).

    So a view is a list of nodes, its adaptable to list only nodes you want to show (filters) and can be setup to appear on a page and or a block.

  3. Fernando Says:

    Question: I have created a new content type with CCK, and I have added two field groups. However, the title and body always appear outside of any groups, and all taxonomy-related fields appear in a “category” group, and there is no apparent way to customize this. I would like to have, for instance, the title and the “categories” group to belong to my first custom group, and the body to the second custom group. Have I managed to explain myself? Any sugestions?

  4. Sean P. O. MacCath-Moran Says:

    Greetings,

    Thanks for this set of tutorials – they provide a nice little push for those (myself included) who are just starting out with Drupal. While I found this set very helpful, I found myself desiring the step-by-step instructions for parts 2 and 3 like those provided in part 1. Adding this in will, IMHO, make for a much more comprehensive and helpful user experience. =o)

    Sean P. O. MacCath-Moran
    http://www.emanaton.com

  5. The Venture Skills Blog CCK & Views the ultimate combination - part 2 « Says:

    [...] Top Posts Top 5 CSS layout tips5 Accessible and pretty CSS tipsWant to create a site like Digg with no programming?Stumbleupon vs Digg – Page layoutsCCK & Views the ultimate combination – part 1 5 Drupal Modules to Guarantee Drupal 5.0 SuccessCreate a site like Digg – Part2CCK & Views the ultimate combination – part 2Stumbleupon vs Digg – Voyeurs vs SheepCCK & Views the ultimate combination – part 3 [...]


Comments are closed.