I have an Ajax handler script where I load a $nodeId
and output the result in default (full) view:
$node = node_load($input);
$prerendered_node = node_view( $node, 'default' );
...
Now I need to display the teaser (summary or trimmed) as well.
I tried this so far, without success (summary is filled in content):
1.
$item = $node->body['en'][0];
$output = field_view_value('node', $node, 'body', $item, 'Teaser');
echo $output; (blank)
2. echo $node->body['eng']['0']['summary']; (blank)
A solution from this question but not working:
3. $output = truncate_utf8(strip_tags($node->body['eng']['0']['summary']),200,true,true);
echo $output; (blank)
Curious is that var_dump($node->body['eng']['0'])
displays and array containing value
(of body), summary
, clean_summary
and other elements and the summary
has the necessary value filled. But as in example 2 I can't directly access it, it's coming up blank on display.
Tips, please?
Thank you.
The correct way to do this without accessing the value directly (so you automatically get an internationalised version I think) is shown below:
$node = node_load($nid);
$body = field_get_items('node', $node, 'body');
$teaser = field_view_value('node', $node, 'body', $body[0],'teaser');
To output the $teaser value, you need to pass it to the render() function
print render($teaser);
JC