I have an array of node IDs with which loop through and run node_load($nid) to retrieve the data for each of those nodes. Take for example the below code- that’s roughly how it works at the moment.
foreach( $node->field_flights['und'] as $flight ):
$flightNode = node_load($flight['nid']);
echo $flightNode->title;
What I want to achieve is to load the node, then be able to do something along the lines of echo render($flightNode); so that it loads the template file for that node and I can render the $title_suffix variable in the node template which has been loaded.
I’ve tried the following to no avail. Nothing is output at all.
$flightNode = node_load($flight['nid']);
$builtFlightNode = node_build_content( $flightNode );
echo render( $builtFlightNode );
Would anyone provide some insight?
You can use
node_view()to prepare the render array. For performance it might be wise to consider usingnode_load_multiple()(and it’s counterpartnode_view_multiple()) like this:If that doesn’t fit in with what you’re doing though this should work on a node by node basis:
If you need to modify the content before it’s rendered, you can just step through the
$viewsor$viewarrays and change what you need to before running it throughrender(). If you just want a particular part of the node content rendered, again just step through the array and applyrenderto the particular sub-array you’re interested in.