Posted by x2222 on March 30, 2008 at 6:24am
Jump to:
| Project: | Content Construction Kit (CCK) |
| Version: | 5.x-1.1 |
| Component: | General |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (won't fix) |
Issue Summary
I have a quick question, it seems soo simple but I don't see an option for it. I'd like some text to always display at the top of a particular node type (Not in the content form, only atop the published node itself). The only text fields that I can add in CCK appear in the content creation form and are accompanied by a standard text box for a response.
All I need is the ability to create a static text field in CCK that shows up only in the published node itself. Anyone have any ideas for this? Thanks.
Comments
#1
Well, there's several ways to do this.
Option 1: the theming layer: modify node.tpl.php
- open up node.tpl.php (this is the template file that will be used for each node that is displayed)
- add the static text where you want, but wrap it in a bit of php where you check for the node type, so the text is only included for your specific node type
- downside: if you add too much conditional statements here, your node.tpl.php will become hairy and unmanageable
- for example: let's say you want to add some text when the node type is 'mynodetype'
// add this custom bit
if ($node->type == 'mynodetype'){
print "this is some static text";
}
// end of the custom bit
// this what happens most of the time in node.tpl.php at some point:
if ($content){
print ($content);
}
Option 2: the theming layer: use a specific template file for your node type
- make a copy of node.tpl.php (found in your theme folder) and call it node-mynodetype.tpl.php, where mynodetype is the name of the node type in question
- open up node-mynodetype.tpl.php and add the static text where you want
- in my opinion the preferred way
Option 3: custom code in your own module
see http://groups.drupal.org/node/2403
#2
Thanks a lot for you help. I really appreciate your comment.
#3
Just chiming in -- a static text CCK type would be very useful. I have this same use case, except I'm sure my client will want to change the header text several times and they should be able to just do it by editing it the content type rather than having to open up a tpl.php template file, or more likely having me do it.
Cheers.
#4
Yes, I think a static content type CCK field is needed to add comments, instructions, notes etc. in between form fields.
#5
Once you create a separate node.tpl.php file for your node type, how do you arrange for it to be called and display that node type?
#6
A quick and easy way I've used to achieve a static text field is to use the Computed Field module to output your static text. A bonus of that is you can also do dynamic text (i.e. look stuff up in the database).
#7
Here's a decent idea depending on your needs: http://drupal.org/node/540232
#8
Closing old issues. None of us is using the D5 version any more, so hard to provide any support. Sorry.