I've had many problems trying to create a theme in D7 that shows specific content in specific styles, and in order to solve one small part of it, I've got this conundrum:

I've create a custom content type (product), with several custom fields.
- One custom field (field_overview_text) appears fine when displayed in a view, as a block.
- When I try to render it in node--product.tpl.php, it doesn't appear using this format:

print render($content['field_overview_text']);

- While other custom fields of the same type (Long text), appear fine:
print render($content['field_product_description']);

Debugging with this:
print_r($content['field_overview_text']);
yields nothing, but this:
print_r($field_overview_text);
shows that there is content available:
Array ( [en-US] => Array ( [0] => Array ( [value] => This is my overview text [format] => [safe_value] => This is my overview text ) ) )

P.S. The reason I'm doing it this way, rather than just use the view/block method, is that in this region I want to fall back and display the (title) field if my custom field (field_product_title) is empty. Couldn't find a way to do that through views...
I'm an experienced PHP developer, but lack of structured/well-indexed documentation and examples for D7 is frustrating to say the least. What I've learned about D7 so far is only from random posts/responses I've found through Google.

Any help on this, and my myriad next questions, would be greatly appreciated!

Comments

ClaudeS-1’s picture

Regardless of whether I can show the "title" field if "field_product_title" is empty, and solve this with Views/Blocks, I think I still need to be able to render "field_overview_text" in my node--product--teaser.tpl.php, as I my Products landing page has to show several product images/overviews on one page.

ClaudeS-1’s picture

OK, I've figured this out, will share my notes in case anyone else struggles with the disconnect between using Views/Blocks to render fields, and using page templates to render fields.

Turns out [Structure » Content types » Product » Manage display] had that [field_overview_text] set to be hidden for the Teaser. So when you use this in a theme template to render a field:
print render($content['field_overview_text']);
it looks at the display settings for the content type.
I found this when trying to render a thumbnail image using a theme template, and couldn't find any help online. I then remembered that you could choose which image size to use, somewhere, and found the Manage Display pages - this let me render a thumbnail image just by using this in a theme template:
print render($content['field_product_image']);
and by setting "thumbnail" as the default image style in Manage Display.

Hope that helps. Slowly, very slowly, getting to understand Drupal. Still wish there was clear documentation for D7 that spelled stuff out for people new to Drupal.

sachbearbeiter’s picture

since drupal 4.x i print fields in a template based clean way - but with the missing documentation for 7 it's really hard to find out the best way ...

zirafa’s picture

Just to follow up with my experience:

I was getting really bizarre behavior with just one custom content field not rendering properly for a regular full node display. My teaser views were handled by Views and seemed to work fine however.

I tracked down the problem to this page:
http://yoursite.com/admin/structure/types/manage/[your-content-type]/display

At the bottom, where it says "Custom display settings" uncheck all the boxes and save. This will force all displays to use the default settings. If you check any of them, you have to manually configure display settings for EACH. If you aren't diligent with knowing and configuring each display setting for each situation, you get unexpected results as it renders differently for each setting, i.e. Teaser vs. Full. 99% of the time you will probably not need this functionality anyhow as you can alter the way fields render using Views or a template file or some custom code, so just save yourself the headache and remove any custom display settings.

arthitst’s picture

thank you. It's work.

streetracersts’s picture

Worked for me. Thanks!

robjob118’s picture

If your 'field_custom_1' field is contained within a field group called 'field_group_1' you cannot simply call that custom field in your template with:

print render($content['field_custom_1']);

You need to call the machine name of the field group 'field_group_1' instead so it would look like:

print render($content['field_group_1']);

This will of course render all fields within that field group.

Hope this helps someone, I spent a couple hours trying to figure out why all the custom node fields were rendering except one.