By vlad-ghita on
Hi there
I hope this is the right category to place the question ...
I have a template which handles Ajax responses for content types which contain a body field with summary. Using this
$node = node_load($input);
$prerendered_node = node_view( $node, 'default' );
I get everything about the node but when I render the body
render($prerendered_node['body']);
the summary isn't displayed. How can I access the summary of body field?
I tried
field_view_field('node', $node, 'summary');
field_view_field('node', $node, 'body', 'teaser');
but it seems I don't know how to use this function. Is there a better way than this?
$node->body['en'][0]['summary'];
Update
Seems that $node->body['en'][0]['summary']; won't even work. It displays nothing, although var_dump($node->body['en'][0]) shows the information.
Thanks.
Comments
Solved
Check the answer here.
A proper answer
Instead of using the body array directly, you should use render() and field_view_field(). When used properly, they would display exactly the same as native rendered output.
You may take a look at these examples:
For more information, please take a look at these:
hi, i'm very interested on
hi, i'm very interested on this, but i can't manage to make it work in my node.tpl.php
in fact i need this to render two "types" of the same field in a same node (one is 'default' and the other 'text_summary_or_trimmed')
but i guess there's something i don't understand as this breaks all my node:
thanks for helping !
oups, in fact it works
oups, in fact it works perfectly in a node.tpl.php, my problem is that i was trying to do this within a field-collection-item.tpl.php...
so it's another issue, but if you have a solution for this...
Use $body varible
in the node--my-content-type.tpl.php file the body variable is accessible. So, you can use something like this:
This will work
Use the below code to print summary in your custom page: