Skip to content

Instantly share code, notes, and snippets.

@jlogsdon
Created September 2, 2009 15:43
Show Gist options
  • Save jlogsdon/179776 to your computer and use it in GitHub Desktop.
Save jlogsdon/179776 to your computer and use it in GitHub Desktop.
<?php
/**
* Implementation of hook_theme()
*/
function module_theme($existing, $type, $theme, $path) {
$theme = array();
$base = array(
'path' => "{$path}/theme",
'file' => 'theme.inc'
);
$theme['search_results'] = $base + array(
'template' => 'search-results',
'arguments' => array('nodes' => array(), 'type' => null),
'pattern' => 'search_results__'
);
$theme['search_result_item'] = $base + array(
'template' => 'search-result-item',
'arguments' => array('node' => null, 'type' => null),
'pattern' => 'search_results_item__'
);
return $theme;
}
/**
* Page callback with theme() calls
*/
function module_display_results() {
// Assume a query has been run and $node_ids is an array of node ids to load
$type = 'page'; // Type of node
$nodes = array(); // Collection of themed nodes
$item_templates = array('search_result_item__'.$type, 'search_result_item');
$result_templates = array('search_results__'.$type, 'search_results');
foreach ($node_ids as $node_id) {
array_push($nodes, theme($item_templates, node_load($db_result['nid']), $type));
}
return theme($result_templates, $nodes, $type);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment