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
Comment #1
doeboy commentedComment #2
doeboy commentedHi
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-> ....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.
Comment #3
markus_petrux commentedIf 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.
Comment #4
Dret commentedAt 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:
... but making this change: foreach ($field_nameofmyfield as $delta => $item)
And it works good...
The problem are the labels, here the code:
How I have to modify this code to obtain the value of a particular CCK content label name and position?
Thanks a lot!
Comment #5
Dret commentedI have found a better solution for the first one example above:
To print all value for a single field....
But i still can't find solution for labels...
Comment #6
markus_petrux commentedYou need to ask CCK for the field label. Here's a snippet to do it:
Comment #7
Dret commentedThanks a lot! It works...!
There's a possibility to recover also the settings for "inline/above" position, stored originally here??
Bye!
Comment #8
markus_petrux commentedOh, 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.
Comment #9
Dret commentedI 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):
Do I made something wrong?
Bye!
Comment #10
pinxi commentedTrying something similar with displaying multi cck fields that can have multi values. Was thinking of something like:
But this just shows the titles and not the artists:
I tried working with this but couldn't figure it out:
Thanks for your help!