Render single node field


/ Published in: PHP
Save to your folder(s)

Render the contents for a single node field.


Copy this code and paste it in your HTML
  1. // Full render, including value & labels
  2. $node = node_load($nid);
  3. $node = node_build_content($node, FALSE, FALSE);
  4. $rendered_field = drupal_render($node->content['field_name_to_render']);
  5.  
  6. // Populate the node "view" values as if it was on a node template
  7. // Puts rendered values in $node->{field_name}['view']
  8. $node = node_load($nid);
  9. $node->build_mode = 'full node';
  10. $node = node_build_content($node);
  11. drupal_render($node->content);
  12. content_alter($node);
  13.  
  14. // Render just a field
  15. $result = content_format({field_name}, $node->{field_name}[0], '{format_name}');
  16. // {format_name} can be found from the output of:
  17. content_fields('{field_name}', '{node_type_name}');

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.