In the latest Drupal Podcast, JonBob and I talked about CCK. One of the things that we talked about were the problems getting the CCK field information to display nicely on pages and particularly in RSS feeds. We talked about creating a forum topic so that people could give some feedback on this subject. Here it is!

Comments

Well in the true "scratch your own itch" style, I've written a module called Content Templates (a.k.a. contemplate.module) that attempts to solve the problem of pretty-fying CCK output. But I've written it, so that it can actually work for any node type allowing modification of the node teaser and body output without having to create theme-based template files.

Check it out. I'd love some feedback.

--= Jeff Robbins | www.lullabot.com =--

--= Jeff Robbins | Lullabot | Do It With Drupal =--

i just installed it and it works fine.

I'm interested to see how this evolves...

Thanks for the module Jeff, I spent an age making a new content type, and then populating pages only to find that there was no teaser, this should be part of the main CCK module I reckon.
PS love the lullabot podcasts!

Somehow the signup modules nodeapi isn't called properly, so it stops displaying the signup form.

TIP: If you use nodereference, and needs to display a field from within the node youre referencing, you can use the node_load($nid) to fetch an array of all the contents of the node. Quite handy for fetching, ex. prices on an associated products listing. Horray for drupal, cck and content templates :)

doh. I just discovered this as well. any way to force/trick the signup nodeapi method to be properly called? I've tried dropping a direct call in my contemplate template for the affected signupabble node type. No dice.

Is this a way to create templates for authoring microformats similar to what Structured Blogging provides? GoingOn (a drupal site) also provides the same sort of support and functionality.

Are there any templates available or in the works?

Any insight will be most appreciated!

---------------------------------------
Gus Austin

Hello all,

Installed Contemplate and this is what I'm finding:

- i can get to the administrative screen (displayed under "Administration" as "Content templates"). Initially, the list did not display any of my configured content types -- neither the defaults nor the ones I created. After some debugging, it seemed that the reference to the
I had to enter into the code and twiddle the code in line 112 of contemplate.module to at least see my content types:

OLD:

<?php
 
foreach($types as $type => $name){
  
$rows[] = array(
     
$type->name,
     
l($templates[$type->type] ? t('edit template') : t('create template'), 'admin/content/templates/'. $type->type),
    );
}
?>

NEW:

<?php
 
foreach($types as $type => $name){
    
$rows[] = array(
     
$name,
     
l($templates[$type['type']] ? t('edit template') : t('create template'), 'admin/content/templates/'. $type),
    );
}
?>

I'm guessing this is wrong -- the original code has object references and the modded code is referencing the actual strings that contain the names so that it can create the path...

This does give me the proper list of content_types and the correct URL to create, but then I get an error out of PHP when drupal_get_form('contemplate_edit_type_form', $type) gets called within contemplate_edit_type()

[Wed Nov 29 09:13:02 2006] [error] PHP Fatal error: Unsupported operand types in /array01/shc_servers/[path to]/form.inc on line 98

drupal_get_form expects an reference to an array containing the actual form structure and I'm passing it merely a string...

Environment info:
drupal 4.7.4
PHP 4.4.2
mysql 4.1.18-max-log

Other modules that could throw wrench:
i18n (have to manage a multilingual site)
translation
category

Anyone have any bright ideas?

-jfr

i can get the content type list qith your code bud when i click on "create template" i get this error:

Fatal error: Unsupported operand types in /var/www/provincia/includes/form.inc on line 98

I used the content template engine to tweak my template

I saw $_workflow in the body of variables . but when i add it to the teaser or the body it prints the no instead of the lable. how do i print the label

I've only had it for five minutes and I'm hooked! This is a tremendously beneficial module...should be part of CCK proper.

The template system works very good. Since you asked :) I have one suggestion.

I'm trying to create a press-release node. I'd like to use a single text area for the body and also have use of the drupal <!--break--> functionality to create the teaser. However, it appears as though the break statements are ignored.

That being said, I also like the feature of being able to include one or more fields in the teaser.

A nice compromise that would also work like existing nodes would be if each field could have a druapl break, with the remaining content being ignored in the teaser.

After playing around with it for a while, I'd say this module is indispensible for users of CCK. That said, I still have no idea to create a teaser. I get the impression from this page that it may not even be possible. Does anyone have a suggestion as to how to automatically generate teasers and theme them with Contemplate?

I am glad Contemplate was made available last week so i could completed a small site i did
http://vdbaby.com/contest/contestants

you should be able to create teaser or any field for that matters using both CCK and Contemplate. I created teaser, thumbnails field using CCK. I then use Contemplate to create a template and apply whatever field i would like too and have it displayed like the above example.

But how did you create the teaser in the template? Dropping in $teaser doesn't work. Is it not being automatically generated?

assuming you have both CCK and Contemplate installed.

first creating content type using CCK:
administer > content > content types > i created new content type, add new fields (for instant fields called "teaser" and "body")

then creating template using Contemplate:
administer > content > templates > you should see your content type created above > create template > you should see teaser and body of Contemplate: here you see both "teaser" and "body" fields listed, you then can remove the "body" field in teaser and vise versa.

That's kind of hacky. A developer has released a patch that adds automatic teasers to CCK, but his patch is for a version that is two months out of date. I tried adapting it, but kept running into a fatal error.

I think I'm going to use Contemplate to do a regex search on the "body" field and manually rip out the first paragraphy. That's pretty hacky, too, but when the patch finally enters CCK's core, I can just take the code out of my template.

Thanks for the help, though.

I am a couple of weeks into hacking at Drupal for the first time and I am having some trouble that this module appears to fix. I am using the "front page" module so I am generating a list of CCK nodes by hand, but no matter how I do it the nodes I generate don't seem to have what I need in them. What is the proper way to create a node and display it so the theme will remain intact (including the templates from this module)?

I have been using code to generate my list of nodes:

$result1 = pager_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = '$content_type' AND n.status = 1 ORDER BY n.created DESC"), $listlength);
while ($node = db_fetch_object($result1)) {
  $output .= node_view(node_load(array('nid' => $node->nid)), 1);
}
print $output;

This works but displays the entire content of the node, this post helped me realize why I couldnt grab ->body and manipulate it directly, and why there is no ->teaser. Any help/suggestions would be appreciated!

Hey Blizzo,

Did you ever get an answer to your question? I have the same issue...

----------------------------------------
Chuck Crandall
WebChuck Web Development
chuck at webchuckweb dot com
----------------------------------------

are any of you trying to make a site where public sees teaser and paid members see full listing?

I have CCK and Contemplate installed. I've created a couple new content types with CCK, and of course, want the output to look better.

But, I'm completely lost as to how Contemplate can help me.

Yes, I created a template for the content type in question, but when editing the template, I just have no idea what I'm looking at.

Maybe this isn't what I'm thinking it is. I want to be able to change it so the field headings are left justified and use a bolder and/or larger font than normal. I've tried editing CSS files, and using the recommendations in the very brief CCK readme, but nothing ever changes. This really needs to be easier. If you have to be an expert PHP programmer (I have programming experience, but do NOT feel like coding every template. I went to Drupal to hopefully avoid this type of thing) then these types of modules will only appeal to a small number of Drupal users.

What am I missing? What is Contemplate supposed to do for CCK??

Steel Rat
Drupal Site: RPGMapShare.com

Hi,
No, you don't need to be a programmer to use Contemplate.

It is really easy to use it to define teaser display, and full node display.

Once installed, go to administer / content / template. Choose the content type you want to theme.

You will be presented with two fields: one for the teaser, one for the full display. Each will support some tags that are shows on the right. You can use these tags anywhere in teaser or full node.

Only problem is that contemplate doesn't work since last cck changes :(, at least for existing templates.

Cordially,
Brakkar

But I still don't understand how I can get those contemplate tags to actually alter the CCK node display. Should the CT tags replace the output in the left field? Add to it? It just isn't intuitive at all, not to me anyway.

I'll keep fiddling with them.

Steel Rat
Drupal Site: RPGMapShare.com

Used contemplate as well and love it!! It makes things a lot easier to just go into my specific content type taht I want to change and enter a little code in the provided spaces to change the layout. After days of figuring out how to do this... this was an awesome find!!

Now.. I would like to create a page of a list of content in a specific content type.

For example: content-my_page

I would like to show certain feilds within that content type. Similar to a user list but with fields from this page. I was thinking that something like the php snippets for showing these feilds would work, but all I can get is a snippet for showing the title of each content created within that type.

~~~~~~~~~~~~~~~~
Kris
Current project: www.cribfax.com

~~~~~~~~~~~~~~~~
Kris
Current projects: www.cribfax.com
www.myabatherapist.com

Hi,
when did you last updated you cck ?

Cordially,
Brakkar

I just installed it about 2 weeks ago. I thought maybe there was something wrong with views (as I tried to create a views page with the cck content) so I reinstalled that but dosen't seem to work when I want it to pull out the feilds from the cck page I created.

It seems like it should be easier so I may be doing something wrong, but I have checked everything!!

~~~~~~~~~~~~~~~~
Kris
Current project: www.cribfax.com

~~~~~~~~~~~~~~~~
Kris
Current projects: www.cribfax.com
www.myabatherapist.com

Is anyone else having a problem with CCK not having a teaser (where it DOESNT say "read mroe" on the bottom?) or is it just me.

I'm having the exact same problem and everyone is talking throughout the forums about the problem but with no solution (that I can see)

I'm using the code similar to what the guy earlier in this thread is using; it prints the whole article and not teasers for CCK types promoted to the front page. And no one is saying how to print teasers.

$result1 = pager_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = '$content_type' AND n.status = 1 ORDER BY n.created DESC"), $listlength);
while ($node = db_fetch_object($result1)) {
$output .= node_view(node_load(array('nid' => $node->nid)), 1);
}
print $output;

ok I'm not sure why no one posted this before but I finally figured it out just now and am happy to share with everyone.

here is what i put in my node.tpl.php file (if the code doesnt show up well just view source

<?php
if ($page == 0) {
  
?>

      <div class="node<?php if ($sticky) { print " sticky"; } ?><?php if (!$status) { print " node-unpublished"; } ?>">
    <p align="left"><?php if ($picture) {
      print
$picture;
    }
?>
</p>
    <?php if ($page == 0) { ?><h2 class="title"><a href="<?php print $node_url?>"><?php print $title?></a></h2><?php }; ?>
    <span class="submitted"><?php
           
print 'Submitted by ' . theme('username', $node) . ' on ' . format_date($node->created, 'custom', 'm/d/y') . ' at ' . format_date($node->created, 'custom', 'h:i a');
            if (
$terms) {
                print
' | Tags: ' . $terms;
            }
?>
</span>
<div class="content"><?php print $teaser = substr($field_body[0]['value'], 0, 400) ?></div><span class="submitted">&raquo; <a
href="<?php print $node_url ?>">read more</a> | <?php print $links?></span></div>
   <?php
} else {
  
?>

       <div class="node<?php if ($sticky) { print " sticky"; } ?><?php if (!$status) { print " node-unpublished"; } ?>">
    <p align="left"><?php if ($picture) {
      print
$picture;
    }
?>
</p>
    <?php if ($page == 0) { ?><h2 class="title"><a href="<?php print $node_url?>"><?php print $title?></a></h2><?php }; ?>
    <span class="submitted"><?php
           
print 'Submitted by ' . theme('username', $node) . ' on ' . format_date($node->created, 'custom', 'm/d/y') . ' at ' . format_date($node->created, 'custom', 'h:i a');
            if (
$terms) {
                print
' | Tags: ' . $terms;
            }
?>

</span>
    <div class="content"><?php print $content?></div>
    <?php if ($links) { ?><div class="links">&raquo; <?php print $links?></div><?php }; ?>
  </div>
   <?php
}
?>

everything works... except that the teaser doesn't show. started troubleshooting but i tried the contemplate module one last time and it works perfectly. i'm just working on getting a "read more" or "read rest of article" link and it's perfect.

- Jason

...over here: http://drupal.org/node/86398#comment-158152. It should help.

The problem with something like that is you're abusing the "$page" variable. There are legitimate situations where page == 0 and it's not supposed to be a teaser. For example, previewing a node.

Instead, test whether $teaser == 0 or $teaser == 1. (i.e. your test for $page == 0 should be $teaser == 1) and vice versa. This works (at least) in 5.0 rc 1. I don't know if it's the same in 4.7.

This one took me hours to figure out....

Related Idea: http://drupal.org/project/nodeprofile

Building a profile out of nodes allows using CCK and its field types as well as the CCK form builder. For a maximum of flexibility it'll be also possible to use custom node-types and modules instead of the CCK. Integration of the views module allows to easily build customizable user listings or even user search. Making users available as nodes also offers additional benefits, which are currently only available for nodes, think of using taxonomy, node comments or searching by field with users.

I updated my CCK on 30-06-2007

I've been playing with contemplate/CCK nodes/Views to create an RSS feed to 'power' a GoogleMap view of my nodes. Using the theming capabilities of contemplate, I can get a 'clean' output of my InfoWindow on the map (or so it seems for now).

However, when I view the raw output of the xml file it still displays a lot of 'overhead' (won't use that other word).

What I wat is a 'clean' output of just the xml data I need and nothing more. See also the posting by mikesuttie at http://drupal.org/node/83933 where he gives more or less the layout what I need.(going to crosspost)

Kitealtas posted an inssue on the subject (http://drupal.org/node/87027), without any followup.

Is there any (new) information on how to format the feed itself?

I've posted a possible sollution to the messy RSS produced by using CCK + Views (caused by CCK not using a teaser)... http://drupal.org/node/87430

haha, I commented on your solution first, thanks for the heads up anyway!
Boy, is this hot off the press ;-)

Hehe - I actually posted here because you posted in mine saying that mine is a possible sollution to these.

I think its a fairly big problem... CCK should implement a way of selecting which field defaultly acts as the teaser - possibly in the same way it does with title?

How to use Teaser Template & Content Template

Hey guys,

I want to create a bunch of similar pages (same layout, sections, etc), but with different content. I had ago at using contemplate to do this but have not had any luck. It seems that if I create a template then the body field of the node is ignored. Doesn't this defeat the purpose of having a template? Is there any way contemplate (or any other module) can write a template into the body field of a node, which anyone can then edit?

I did find the node template module, but it doesn't work for Drupal 6.

Cheers!