function contemplate_eval in Content Templates (Contemplate) 7
Same name and namespace in other branches
- 5 contemplate.module \contemplate_eval()
- 6 contemplate.module \contemplate_eval()
Copy of drupal_eval(), but extracts the node object so that variables are available to the template
Parameters
$tmplt: text the template code
$obj: object an object to extract into the local variables
Return value
string executed template code
4 calls to contemplate_eval()
- contemplate_ajax_preview in ./
contemplate.module - provide ajax callback for template editors
- contemplate_eval_enclosure in ./
contemplate.module - Eval the RSS enclosure field
- contemplate_node_view in ./
contemplate.module - Implements hook_node_view().
- contemplate_preprocess_node in ./
contemplate.module - Implements tempalte_prerocess_node().
File
- ./
contemplate.module, line 848 - Create templates to customize teaser and body content.
Code
function contemplate_eval($tmplt, $obj, &$xml_elements) {
global $user;
extract((array) $obj);
$node = $obj;
// attempt to get the language that we need to display to the user
// default to the node language
$default_language = language_default('language');
$display_language = !empty($user->language) ? $user->language : $default_language;
$node_language = !empty($node->language) ? $node->language : 'und';
$language_to_display = isset($node->body[$display_language]) ? $display_language : (isset($node->body[$default_language]) ? $default_language : $node_language);
//CCK supports nodes without body.
$teaser = isset($node->body) ? $node->body[$language_to_display][0]['safe_summary'] : '';
$body = isset($node->body) ? $node->body[$language_to_display][0]['safe_summary'] : '';
ob_start();
print eval('?>' . $tmplt);
$output = ob_get_contents();
ob_end_clean();
return $output;
}