CCK - Display of teaser and full version using field formatters
jameson - August 2, 2007 - 20:23
As soon as the ?php print $content? is removed from the template and the '?php print content_format('field_whatever', $field_whatever[0]); ?' inserted then the ability to use CCK's Teaser view and Full view is lost.
For example in my content type I have a field_short_description set to display in Teaser while for Full it is Hidden.
How would I get the below script to understand CCK's Teaser and Full?
<?php
print content_format('field_short_description', $field_short_description[0]);
?><?php
print content_format('field_description', $field_description[0]);
?>Does anyone have an example piece of code that will pick up cck's field displays - teaser and full?
Much appreciated.

contemplate module have the
contemplate module have the ability to set different templates for both teasers and nodes.
<?php print
<?php print $node->content['field_field_name']['#value'] ?>I think it becomes something similar
[#value] only prints the
[#value] only prints the value of the field. So if it has a special formatting, it won't be formatted with that.
$field_name[0]['view']
I believe $field_name[0]['view'] has the formatted text. So if the name of the cck field you created is foo, then $foo_field[0]['view'] contains the formatted text you want.
There is a helpful function which displays all available variables for you in a .tpl.php file, you'll have to see if you can find it here, I don't remember the location in the handbook where it describes it.
Dave
My site: http://www.unitorganizer.com/myblog
lol i just saw that !! lemme
lol i just saw that !! lemme check history
BTW, how do u format a field?? oh i think i might have seen that too
EDIT3: http://drupal.org/node/191796
how do u format a CCK field?
how do u format a CCK field?
I did exactly what you want to do:)
Hi there....
Take a look at this very helpful link: http://www.davidnewkerk.com/book/30
Read the section on "Custom theming for node-article.tpl.php". It will tell you what you need to replace the
<?php print $content ?>with. You can replace it with<?php print $node->content['body']['#value'] ?>for the full node section of your node.tpl.php. (Read further below and this will make more sense to you:)(In fact, I would bookmark David's website...it has a LOT of VERY VERY handy info up there!! It really helped me out when putting my site together.)
Here is an example of some code STRUCTURE for your node.tpl.php section you can use as an example template (given to me by yelvington, another user.) I modified this for each of my sections on my site. I used this (along w Views and CCK) to customize how I wanted my teasers vs my full View/node to look.
In Views, I chose to display the View (of each section) as node, and not fields, then customized the node.tpl.php to get it to look exactly the way I wanted.
<?php if ($page == 0): ?><!-- this is a list or view, not a single node.-->
<!--Put everything you want for your teasers in here, including your field_short_description. -->
<?php else: ?>
<!-- This is your full node. Put everything you want for your full node in here. -->
<?php endif; ?> <!-- end of the code for the teaser AND full node. -->
<!--Here, put everything you want in both teasers & full node. -->
<?php endif; ?> <!-- the is the end of the whole $page scenario. including the "else" -->
Here is an example of one of my node.tpl.php files, the one for my articles section (for the teasers and full node) at (you can view how it looks at http://74.220.215.68/~leemagaz/articles . Pls. note that it is currently under heavy construction so most of the text in the stories is just "dummy text" :) :
<div class="node <?php print $node_classes; ?>" id="node-<?php print $node->nid; ?>"><div class="node-inner">
<?php if ($page == 0): ?><!-- this is a list or view, not a single node -->
<h2 class="title">
<a href="<?php print $node_url; ?>"><?php print $title; ?></a>
</h2>
<?php if ($picture) print $picture; ?>
<?php if ($submitted): ?>
<div class="submitted">
<?php print $submitted; ?>
</div>
<?php endif; ?>
<?php if ($field_image_primary): ?>
<div id="image_primary_thumb">
<?php print $node->field_image_primary[0]['view'] ?>
</div>
<?php endif; ?>
<?php if ($unpublished): ?>
<div class="unpublished"><?php print t('Unpublished'); ?></div>
<?php endif; ?>
<?php if (count($taxonomy)): ?>
<div class="taxonomy"><?php print t(' in ') . $terms; ?></div>
<?php endif; ?>
<?php print $node->field_article_teaser_text[0]['view'] ?><!-- this is the code for my teaser text field, like the short description you have -->
<?php if ($links): ?>
<div class="links">
<?php print $links; ?>
</div>
<?php endif; ?>
<hr>
<!-- end of the code for the teasers, beginning of the code for the full node -->
<?php else: ?>
<?php if ($field_subtitle): ?>
<div class="field-field-subtitle">
<?php print $node->field_subtitle[0]['value']; ?>
</div>
<?php endif; ?> <!-- end of the code for the "either teaser/OR full node". Code for what needs to appear on BOTH teaser & full node begins below -->
<?php if ($field_image_primary or $field_image_primarytext): ?>
<div id="image_primary_main">
<?php print $node->field_image_primary[0]['view'] ?>
<span class="cutline"><?php print $node->field_image_primarytext[0]['view'] ?></span>
</div>
<?php endif; ?>
<?php if ($picture) print $picture; ?>
<?php if ($submitted): ?>
<div class="submitted">
<?php print $submitted; ?>
</div>
<?php endif; ?>
<?php if ($unpublished): ?>
<div class="unpublished"><?php print t('Unpublished'); ?></div>
<?php endif; ?>
<?php if (count($taxonomy)): ?>
<div class="taxonomy"><?php print t(' in ') . $terms; ?></div>
<?php endif; ?>
<?php print $node->content['body']['#value'] ?> <!-- this displays the content of the body. -->
<?php if ($links): ?>
<div class="links">
<?php print $links; ?>
</div>
<?php endif; ?>
<?php endif; ?> <!-- the is the end of the whole $page scenario. including the "else" -->
</div></div> <!-- /node-inner, /node -->
I hope this helps!!
P.S. Imagecache & Imagefield were used in tandem with CCK for the teaser & main images:)
My other thread here at http://drupal.org/node/290667 may be of additional help to you:) That was as I was trying to customise the node.tpl.php to get everything the right place.
Best regards,
Christine
P.P.S. I just saw your post was a month old! I hope this will still be of SOME help at least:) Better late than never...
Would this help?
Would this help? http://drupal.org/node/92382