Not sure what's causing this problem, but it is easy to replicate.
1. Load Drupal 4.7.4 and install and enable CCK 4.7.x-1.0 with the various fields
2. Create a content type with Label = "Store" Title Field Lable = "Sushi Store"
3. Create one field of type Text - Text Field
4. See the attached screen shot to make sure your fields are correct
5. You just loaded Drupal so you're using the default Bluemarine theme files
6. Create new content of type Store and add some html (you'll probably have to configure the input types to allow HTML)
7. Now, go to the node you created. You will be able to click on the view tab to view the rendered HTML you entered. You'll also be able to click on edit and edit the HTML in a form as usual.
8. Go to the bluemarine theme directory.
9. copy page.tpl.php file to page-default.tpl.php
10. edit page.tpl.php and change the contents to this:
if ($node->type == 'content_sushi_store') {
include 'store.tpl.php';
return; }
include 'page-default.tpl.php';
return;
11. copy page-default.tpl.php to store.tpl.php
12. Edit store.tpl.php and change this line:
print $content;
to this line:
print $node->field_store_body[0]['value'];
13. Now go back to the node and view it. It views ok, but when you
click on the edit tab, the rendered HTML will display instead of the
HTML inside a form.
| Comment | File | Size | Author |
|---|---|---|---|
| list_1.png | 17.07 KB | slimandslam |
Comments
Comment #1
karens commentedThere is no bug. You have misunderstood a couple important concepts (and I know that this can be confusing so that isn't meant as an insult).
1) Do not EVER put anything like the following in your templates, especially with a field that might contain html or php code:
Instead use:
There could be invalid or badly formatted html in that field, or worse, it could contain an exploit that could cripple your site.
2) Do not print your field info in the page template, print it in your node template. When you wipe out $content in your page template on the edit page, you have wiped out everything on that page, including your edit form.
Comment #2
slimandslam commentedHi Karen. Thanks for your feedback
1) If you look in the "theme" directory inside the CCK module release, then
look at the node-content_example.tpl.php file. It has:
print $field_body[0]['view'];that's where I got the idea of putting a value directly in a template.
2) I tried creating a template named node-content_sushi_store.tpl.php and using
print content_format('field_store_body', $node->field_store_body[0]);in it. However, it still seems that the form is wiped out.
The total lack of a few decent *simple* usage examples is quite frustrating.
Do you have some suggestions?
Comment #3
karens commentedYou can put it in a template, but only the node or field templates, not the page template. If you put it in the node template and put print $content back into the page template it will work. I suspect your page template is still missing print $content.
Try reading through the CCK Handbook section on themes (http://drupal.org/node/101723) and hopefully it will explain things more clearly. That handbook still needs lots of work, but it may give you some help.
Comment #4
slimandslam commentedHi Karen,
I've read through that section a few times. The reason it's confusing is because it doesn't
provide any full examples with all the file names and file contents involved. I can't see
how files are getting referenced and loaded.
That said, all I want to do in my case is display one field:
print content_format('field_store_body', $node->field_store_body[0]);on a page that is different from all other pages on my site. I don't understand
why this is so difficult. So, I need a custom page template, let's call it page-store.tpl.php
and I guess I need a custom node template, let's call it node-store.tpl.php. So, in page.tpl.php,
I have the "if" statement below with
if ($node->type = "sushi_content_store") include page-store.tpl.php
But maybe that's wrong? How do I get node-store.tpl.php to show up as the content on
that page? I guess I'm fundamentally missing something.....
Comment #5
karens commentedYou can create a different page template for nodes of a certain type. No problem with that. Just don't put your field info in the page template. Any page template must have $content printed somewhere in it. $content is automatically created by the system and will automatically include the node template on the right pages. Print your field info in the node template.
Comment #6
(not verified) commented