Creating a CCK and Views powered Drupal site
The goal of this guide is to take you step by step through the full process of using Drupal’s CCK and Views modules (as well as a number of other supporting modules) to create customized content types (e.g. news posts, articles, etc), as well as “listing” pages and blocks to display teasers of your content, and then theming everything to look exactly as you intend.
For the purpose of this lesson, a new Content Type called “Article” will be created, and a number of custom fields will be added to it. You can, however, apply this lesson to any other content type you wish to create or have already created. For full control, specific fields will be set up ahead of time for the content type using CCK, so that certain specific fields will be displayed in the teaser view but not on the full page view of the Article content, and certain fields will show only on the full Article pages but not in the teaser views of the content.
Please do not be alarmed at the length of this guide - its length is only due to very thoroughly described steps to make this guide as beginner-friendly as possible. Each step is numbered so you can more easily keep track of your place in the guide.
After completing this lesson, you will have built up skills working with CCK, Views, theming (including theming of a specific content type, use of the Contemplate module, and Views theming), as well as knowledge of Pathauto and Custom Breadcrumbs.
A planned expansion of this article will include the addition of a thumbnail image in the teaser with the full size image in the article itself (using Imagefield and Imagecache), including all the theming code necessary.
Tips on using this guide
- Buttons, links, menus, etc which you are to click on are written within “Quotes”.
- The names of options/settings, when referred to, are shown in Italics.
- Options you are to select or text/code you are to enter into setting/configuration fields or your template files are
highlighted. When you see highlighted text, you should copy/paste it into the specified settings field or template file on your site. - When the guide calls for you to navigate to a certain administration page of your Drupal site, the path is shown in this format: Administer > Site building > Blocks and the URL is also provided (admin/build/block).
- Occasionally, when there are alternative techniques or other guidance, a Note: will be included.
Requirements:
- This guide has currently been written and tested for Drupal 6… it will be checked and updated with any notes about Drupal 5 compatibility in the near future.
- The examples in the guide use the Garland theme, since all Drupal users have it. You can apply the steps in this guide to any theme you wish though.
- Modules needed (in order to follow along with the guide): CCK, Views, Custom Breadcrumbs, Pathauto, and Token
I would steer people away from Contemplate. It does a couple of things:
1) you are typing PHP into a browser. If you screw up the PHP, bad things will happen
2) PHP is being stored in the DB. It can’t be versioned, approved, or done anything else with in normal code processes.
I realize that many people find Contemplate an easy crutch to do theming … but in reality, they really really really do need to learn the theming learning if they want this level of customization.
Hi Boris -
Yes, since I first began the article I’ve also decided to steer people away from Contemplate (retaining it, if at all, only for reference if needed). I will actually remove it from the list of modules here on the first page. When you get to the Node Theming portion, you’ll see that I’ve pointed people now to the actual theming code for the fields, showing them the most common theming code snippets and explaining how simple it is to use and reuse them; I’ve tried now to dissuade them from using Contemplate (the first draft of the page focused on Contemplate, but I’ve moved that completely off to a separate optional page that will just explain Contemplate’s possible uses, that it’s preferable just for reference, outline the reasons why it’s NOT good to use it, and provide tips such as if they still choose to use it, to still save its output in real files and not the database). Feel free to comment on that page with details I’ve missed. One thing that would be extremely helpful is if on the Node Theming page you could assist in any way with additional tips on the best/most understandable way to make sense of the output of something like print_r or other methods (as in, are there any good “rules of thumb” on how best to get at the data you’re after and get that into your theme, security concerns, etc).
Thanks for your feedback. I’ll look forward to as many ideas and thoughts as you’d like to share.
- David
I’ve found Contemplate useful for theming the pages by using “template-files” feature. Creating the 3 files, 1 for normal nodes, 1 for teaser and 1 for RSS allows a great amount of customisation. No PHP is stored in the database.
When I think about it, all it really does is split the templates into 3 possible templates for each section. I especially like the teaser and full node separation.