Skip to content

Instantly share code, notes, and snippets.

@bangpound
Created January 1, 2011 21:09
Show Gist options
  • Save bangpound/762008 to your computer and use it in GitHub Desktop.
Save bangpound/762008 to your computer and use it in GitHub Desktop.
Preprocess function to add filtered node body and teaser to template variables.
<?php
/**
* Implement hook_preprocess_node().
*/
function example_preprocess_node(&$vars) {
// The node is reloaded from the static cache to generate new template
// variables that contain just the filtered body and teaser. node_view()
// unsets the node object's teaser or body property depending on the build
// mode, so the node must be reloaded to get these values.
$node = node_load($vars['nid']);
$vars['node_body'] = check_markup($node->body, $node->format, FALSE);
$vars['node_teaser'] = check_markup($node->teaser, $node->format, FALSE);
// This node object has been loaded, prepared and altered. This is the one
// originally passed to the theme. Any further operations on the node in this
// preprocess function should probably use this object instead of the one
// reloaded above.
$node = $vars['node'];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment