Ho to all

That's my problem:

1) I created a new content type called "Article"
2) I created a series of CCK Fileds for the one above (emai, link, nodereference, gallery, ecc.)
3) I created a single theme file for each field created (content-field-field_email.tpl.php, content-field-field_linktpl.php, and so on...)
All works fine...

But now I need a more complex situation:

CCK fields are printed on screen using the variable $content inside the node.tpl.php file.
But the same variable contain also the body text.

I need to separete the info of CCK fields from body.
I know there's a possibilty to print each field separately... but i need something more... this:


<div class="node">
print $node->content['body']['#value'];  / TO PRINT ONLY THE BODY TEXT /
</div>

<div class="other_info">

Here I need a snippet for each CCK field that show data "in according" with templates previously created (see point 3 above). 

</div>

This is a little bit different from suggestions found in documentation and tutorials where is indicated to write a new node.tpl.php file with all the functions to recover data of each field's array.
I would like to use snippets + cck themefiles... but... It's possible to do???

Thanks a lot!
Bye.

Comments

doeboy’s picture

doeboy’s picture

Hi

Possible solution
1. Set the display fields to hidden of all cck fields of [your content type]
2. Create a custom node.tpl.php (node-[your content type].tpl.php)
3. Print in the template file the corresponding variables of your custom fields.

e.g.

print $node->title ; / TO PRINT the title /
print $node-> ....your fields.... / TO PRINT what ever you like /

You could also use the contemplate module to assist.

note: I would avoid using 3) I created a single theme file for each field created (content-field-field_email.tpl.php, content-field-field_linktpl.php, and so on...) unless absolutely necessary. Alternately theme them with css in the node-[your content type].tpl.php file.

hope this helps.

markus_petrux’s picture

Version: 6.x-3.x-dev » 6.x-2.x-dev
Status: Active » Fixed

If you haven't already, install the Advanced help module. It provides information on CCK, Views and many other modules.

You could also use content_format() or content_view_field() functions. See doxygen in content.module.

Dret’s picture

At first... thanks for suggestions... I will try to study both solutions to learn more (I'm not so skilled in PHP!)

Meanwhile I found a "partial" solution... pasting into a node[content-type].tpl file the code of CCK template file made before.
Considering that my CCK field are all multiple value type, I need a recursive function... so I use this part of code:

    <?php $count = 1;
    foreach ($item as $delta => $item) :
      if (!$item['empty']) : ?>
        <li class="field-item <?php print ($count % 2 ? 'odd' : 'even') ?>">
          <?php print $item['view'] ?>
     </li>
      <?php $count++;
      endif;
    endforeach;?> 

... but making this change: foreach ($field_nameofmyfield as $delta => $item)

And it works good...

The problem are the labels, here the code:

  <?php if ($label_display == 'above') : ?>
    <label class="field-label block_display"><?php print t($label) ?>:</label>
  <ul class="<?php print $field_name_css ?>">	
  <?php endif;?>
  
            <?php if ($label_display == 'inline') : ?>
            <label class="field-label inline_display <?php print($delta ? '' : 'first')?>">
              <?php print t($label) ?>:&nbsp;</label>
	<ul class="<?php print $field_name_css ?> inline_display">	
  <?php endif;?>

How I have to modify this code to obtain the value of a particular CCK content label name and position?

Thanks a lot!

Dret’s picture

I have found a better solution for the first one example above:


<?php foreach ($field_nameofmyfield as $nameofmyfield ) { ?>
<li> <?php print $nameofmyfield ['view'] ?> </li>
<?php } ?>

To print all value for a single field....

But i still can't find solution for labels...

markus_petrux’s picture

You need to ask CCK for the field label. Here's a snippet to do it:

$field = content_fields('field_nameofmyfield', $node->type);
print check_plain($field['widget']['label']);
Dret’s picture

Thanks a lot! It works...!

There's a possibility to recover also the settings for "inline/above" position, stored originally here??

<?php if ($label_display == 'above') : ?> 
<?php if ($label_display == 'inline') : ?> 

Bye!

markus_petrux’s picture

Oh, yes. However, it is a bit more tricky. The settings defined through "Display fields" screen can also be found in the $field array returned by content_fields(). Do a var_dump($field) and you'll probably find more useful information there.

Dret’s picture

I tryed with: var_dump($field_nameofmyfield)

But seems there's no info about label position:

Here the result of my test (on an "email" field):


array(2) { [0]=> array(3) {
 ["email"]=> string(19) "xxxxx@xxxxx.xx" ["safe"]=> string(19) "xxxxx@xxxxx.xx" ["view"]=> string(60) "xxxxx@xxxxx.xx" } 
[1]=> array(3) {
 ["email"]=> string(20) "yyyyyy@yyyyy.yy" ["safe"]=> string(20) "yyyyyy@yyyyy.yy" ["view"]=> string(62) "yyyyyy@yyyyy.yy" 
} 
}

Do I made something wrong?
Bye!

pinxi’s picture

Trying something similar with displaying multi cck fields that can have multi values. Was thinking of something like:

<ul>
<?php foreach ($field_title as $title) { ?>
<li><?php print $title['view'] ?> by <?php print $field_artist['view'] ?></li>
<?php } ?>
</ul>

But this just shows the titles and not the artists:

  • Title 1 by
  • Title 2 by

I tried working with this but couldn't figure it out:

<?php print $field_artist_render ?>

Thanks for your help!

Status: Fixed » Closed (fixed)
Issue tags: -cck single field theming $content body

Automatically closed -- issue fixed for 2 weeks with no activity.