Regarding the Content Construction Kit Module

02.09.2006

Updated 5/8/06

The CCK (content construction kit) module was released only 2 days ago. I've been working with it for only the past 2 hours, and I'm ecstatic. In terms of its overall usefulness, I'd say its in the same category as simplenews, views, and tinyMCE (read: no drupal developer, consultant, or amature should be without it).

In many ways, this module will likely signal death for flexinode. Which doesn't really bother me, because I never used flexinode. While flexinode still has more 'flexibility' in terms of defining all varieties of different fields, it has serious themability issues which have prevented me from ever using it. Moreover, where as flexinode created something of a pseudo-node type, CCK creates full fledged node types that have all the options, workflows, and permissions levels. But perhaps most exciting is how easy it is to theme your custom fields. To get you started, I've written a quick tutorial on exactly that:

LIBERATION FROM THE NODE BOX

The fields of your content type can be themed in whatever order and fashion you wish. In this example, we've created a Press Release content type with three defined fields named  body, subheading, and contactinfo.

Step One: Create a press release template by renaming a copy of your node.tpl.php file to node-content-press_release.tpl.php. Note that all CCK content types follow the same format:

node-content-[the name you gave your content type with underscores in place of spaces].tpl.php

Step Two: Let's say that you wanted the press-release's subheading to appear directly above the body. Here's all you have to do:

Delete everything in between the <div class="content"></div> tags, and replace it with the following:

<h4 class="press-release-subheading"><?php print $node->field_subheading['value']; ?></h4><div class="content"><?php print $node->field_body['value']; ?><h3>Media Contact</h3><?php print $node->field_contactinfo['value']; ?></div>

See the pattern? $node->field_"("the name you gave your field")"['value'];

No additional variables are required.  Though you should probably use some CSS to style it up.

Comments

CCK $content, nodevote, and custom node template

I've been reading through just about everything on the drupal community site and cannot find a solution to displaying nodevote on a custom template for a CCK node. I've seen the examples (including the one here) for parsing the taxonomy items individually, but can't seem to break the nodevote out of $content. Its enough to drive a soul to drink. freighttrain

Haven't done any work with

Haven't done any work with node vote. My guess is that it invokes the node_api (in the same manner as book navigation. Translation -- it seems impossible to get it out of $content without using some asty explode, or preg function (I think php's explode($delimiter, $string) would work). 

As for drinking, that reminds me of one of my favorite productivity tips: drink beer late at night while working on open source projects. 

Has CCK Changed since you wrote this

Hello, I have just been setting up a page using CCK with various fields and have discovered that to get them to print I needed to do the following <?php print $node->field_field_name[0][view]; ?> for some reason the text field I created is in a multidemensional array rather than as Nick describes above Hopefully this may help somefolk Tkgafs

Thanks Tkgafs. I just

Thanks Tkgafs. I just updated the article to reflect some changes in the way CCK returns variables to the template. Now, you enter: $node->field_example['value'] as opposed to  $node->field_example['view'].

 I briefly verified this, but let me know if I forgot about something and it isn' working properly.

can you access vocabularies via custom fields

 Is there any way to create a custom field on  a new content type which can have its values inserted from an existing vocabularysay I create a new content type for playsI would like custom fields for Title, Director, Venue, Year, Castbut these already exist as vocabularies so I dont want to re-type into the defined custom fields, but to choose from the values already existing elsewhereI cant see any way to do this in the module but t may just be my in-experience so any advice anyone could suggest would be most helpful tkgafs   

I'd probably use freetagging

I'd probably use freetagging vocabularies that are only available to that particular content type in combination with this technique for displaying the vocabulary terms in the generated node.

I'm trying to do that as well

I have data stored as taxonomy that I want to display in a node. To make database calls to retrieve the taxonomy info every time the node is displayed seems quite hard work ... also I would love to be able to use the views module in all its glory, and views is very limited in its ability to display taxonomy data. The best solution seems to be to store the taxonomy data also as fields within the node when the node is saved. This means no extra database calls when the node is displayed and most importantly means the node works nicely with the views module (since all its data is now accessibile). Do you have any pointers on how to go about creating a cck widget that would store taxonomy info each time the node is saved?

 Thanks for the pointer to

 Thanks for the pointer to the php snippet works beautifully !!I now feel I starting to get somewhere. Only have to figure out the category module and my site will be flying, if I ever get the 120 odd plays and couple of thousand actors names typed in. Hopefully the promise of cms's workflow systems will come to my rescue and I can get some other folk to do the drudge work [sorry that really import and and skilfull task] of data input while I concentrate on working out what fool will volunteer to start scanning old programmes and reviews kept  in a filing cabinet for the last 40 odd years  I'm still having a problem getting tinymce working with cck defined pages but looking at the cck project page I'm not the only one so I'm sure it'll get fixed soon.if anybodys interested have a look at http://cms.dibbletree.com the snippet of code I'm using is below. I'm new to php coding so if anyone can suggest any improvements please let me know. <code><?php if ($terms): ?>    <?php    $cats = array();     $cats[12] = "Year";    $cats[13] = "Venue(s)";    $cats[11] = "Style";    $cats[14] = "Director(s) ";    $cats[15] = "Actors";    $cats[16] = "Actresses";    $var1 = "terms";    $var2 = "term";    $var3 = "lterm";    ?>  <div class="terms">    <table><tr>    <?php        foreach ($cats as $k => $v)        {            ${$var1.$k} = taxonomy_node_get_terms_by_vocabulary($node->nid, $k);            if (${$var1.$k})            {                $res = count (${$var1.$k});                print "<td>$v </td><td>";                foreach (${$var1.$k} as $key => ${$var2.$k})                {                    $res--;                    ${$var3.$k} = l(${$var2.$k}->name, 'taxonomy/term/'.${$var2.$k}->tid);                    print ${$var3.$k};                    if ($res)                    {                        print "|";                    }                }                print '</td></tr>';            }        }    ?>    </table><br>  </div><?php endif; ?></code>  thanks againtkgafs 

wordpress.com i love you!

wordpress.com
i love you!

CCK Download not complete

Decided to try out the CCK from Drupal. Downloaded the cvs version and the Readme plainly says "import cck.mysql and away you go...".(or something like that anyway :)) Guess what, no sql file in the download, just a bunch of .install files. So how do we go about testing this thing? Would love to give it a whirl 'cause it looks like something I could use...

same problem

I'm having the same problem. The .install files appear to generate the intended sql but for some reason they are not triggering ... not sure how they're supposed to work. Email me scott.trudeau AT gmail DOT com if you figure it out..

no sql file needed

I just downloaded and installed CCK on a 4.7 testbed. No sql file needed or mentioned in the readme. Seems to work fine though I haven't really pushed it much.

additionally

we will be trying to expose a lot of the flexibility that you have with the forms api for views as well.

It all just came together over the conference, and it's going to be fairly spectacular =).

The other guys are very true in saying that you ain't seen nothing yet. 

Drupal the Phoenix

Good god man -- its getting ridiculous -- I already noticed hints of change on view and CCK. You know, the Drupal of Dec 05 seems like a boxy, brittle, and inflexible. It takes me 2 hours a day just to keep up with the CVS of the projects! And yet, while that seems like a lot of time, I've found its beginning to save me days of work just to check up on whats happening. I've been building sites since 9am this morning, so I'm brain dead -- but yes -- in keeping with the "meaning" of this time of the year, drupal is having a new beginning -- or rather, drupal has clearly gone phoenix.

 

tell about differences cck and flexinode

I looked CCK but ot Flexinode did not see no difference. tell about their differences?

Does CCK work with v4.7 or

Does CCK work with v4.7 or is HEAD required?

I see no reason why it

I see no reason why it wouldn't work with beta 4. I've been updating all the sites I'm working to head,however.

Fields as prototypes

Perhaps even more exciting is that the fields which you create can be re-used for other node types. For example, if you make a starting date field for one event type, you can re-use it for a different event type as well. Since both types use the same field, you can do "starting date" searches across multiple node types. In other words, the semantic meaning of the field is retained and is reusable. Modules will also be able to define their own field types. CCK has built-in Views support as well.

Actually...

CCK was initially started as a "sequel" to flexinode, and they share much of the same functionality. Your points above apply equally to flexinode --- types are just as real, have permissions, can be themed, etc. CCK greatly improves on the idea by giving you access to terms ($node->contactinfo) vs. identifiers ($node->field_1), and by letting you re-use fields in other content types. In flexinode, if you created a second type that had a "contactinfo" field, that would get a completely different identifier ($node->field_5). In CCK, it remains $node->contactinfo.

Ahh, CCK!

I hadn't realized JonBob had created a project for CCK until he mentioned it here at the con.

There is a very interesting quartet of work going on here between me, JonBob, clouseau/jvandyk and Vertice/Adrian between Views, CCK, workflow/actions and form API that has some pretty exciting ramifications. All of these systems in place and reliant upon one another should create just sick amounts of flexibility.

Tho CCK with Views support, which you now have (even if you are still limited in types available) is already an amazing step. But I gotta say -- you ain't seen nothin yet. The 'widgets' stuff that we hashed out a bit will take Amazing up an order of magnitude. (Essentially it'll let you define the form items for your field types, which'll give you all kinds of great options about select boxes or customized date fields. Etc. Good stuff). 

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options