My searches cannot find adequete documentation for the render and hide methods. which fields am I allowed to hide, that hide() recognizes? I am working from node.tpl.php in my theme, and i can print_r($node) to see many of its fields, but these do not correspond to what i can hide in hide().

for instance, i can get the main body text of a post entry by:

print($node->body['und'][0]['value']);

( which i got by reading the checking the contents of print_r($node) )
however, this field is NOT the same field to pass to hide, to hide the post content. This does NOT work:

hide($node->body['und'][0]['value']);
render($node);

is there a document that shows the syntax of every field that will be accepted to hide() on the page, block, node levels? totally in the dark.

Comments

Andy Britton’s picture

Have you read http://api.drupal.org/api/drupal/includes--common.inc/function/render/7 and http://api.drupal.org/api/drupal/includes--common.inc/function/hide/7?

Not sure if you found those, apologies if I'm telling you how to suck lemons.

goddestroyer’s picture

I had seen those links previously, and i couldn't find them again to post with my original post. As you can see, they don't show much of anything practical of how to use the functions.

I am developing as a subtheme of zen theme, and the comments in the top of node.tpl.php say, regarding the variables for use in the file:

" * - $content: An array of node items. Use render($content) to print them all,
* or print a subset such as render($content['field_example']). Use
* hide($content['field_example']) to temporarily suppress the printing of a
* given element."

I can add

   print( render($content) );

to the file, and i get posts default-rendered.

so it sounds reasonable enough to use "hide()" to customize this node view to hide some elements... but which elements are available? well if $content is "An array of node items" as i'm lead to believe, I would do a print_r($content) to see what is available. This crashes the page and nothing renders at all.

I can use a preexisting example of
hide($content['links']);

and that does indeed hide the links on the entry (read more, comment count..). But what documentation page would I have been reading to know that i could use $content['links']? Where is it listed which items have which fields available for these functions?

if its an array like it says, why does print_r($content) crash the page?

Andy Britton’s picture

These modules might be of use to you http://drupal.org/project/devel and http://drupal.org/project/devel_themer. There doesn't appear to be the exact documentation your looking for and I've spent well over an hour on google and d.o, I think the majority of people find the info your after using the devel/themer module which has been around for some time.

Hope that helps...

Andy

Jeff Burnz’s picture

$content holds a renderable array, which is why you need to use render(). Install Devel module and use this in the node template:

print dsm($node);

That will spit out the entire node object, you can use this to dig into the array.

To render/hide fields just use the field name, such as:

hide($content['field_image']);
print render($content['field_image']);

When you dig into the array you're going to come up with something likes this
print render($content['field_image']['und'][0]['alt']);, but its wrong, instead of und use #items, so to print just the ALT text of this image field you would use:

print render($content['field_image']['#items'][0]['alt']);

You can use variables such as $node->body['und'][0]['value']), but just print them, eg:

print $node->body['und'][0]['value']);

I hope that helps, I'll try to get some docs up for this (more in-depth), the D7 theming guide is being written at the moment, its just a matter of time...

userofdrupal’s picture

Soo did you find anything out about this? I'm looking for the exact same thing. I want to hide the country part of an address field, but when I call hide with a drillled down array then it does nothing.