我正在编写一个自定义Drupal 7模块,它将完全覆盖网站的搜索页面和搜索方法。以下是我到目前为止的情况:
/**
* Custom search.
*/
function mymodule_search_page() {
drupal_add_css('css/search.css');
// Perform a search (not important how)
$result = do_custom_search('foo');
return '<p>Results:</p>';
}
现在,正如您所看到的,它还没有完成。我不知道如何从中正确返回结构化HTML。我如何使用Drupal的内置模板系统来渲染结果?
答案 0 :(得分:2)
你必须使用drupal内置函数。我希望你正在寻找像http://api.drupal.org/api/drupal/includes!common.inc/function/drupal_render/7
这样的东西答案 1 :(得分:0)
这就是我最终做的事情:
/**
* Implements hook_menu().
*/
function mymodule_search_menu() {
$items = array();
$items['search'] = array('page callback' => 'mymodule_search_page',
'access callback' => TRUE);
return $items;
}
/**
* Mymodule search page callback.
*/
function mymodule_search_page() {
$variables = array();
// Add stuff to $variables. This is the "context" of the file,
// e.g. if you add "foo" => "bar", variable $foo will have value
// "bar".
...
// This works together with `mymodule_search_theme'.
return theme('mymodule_search_foo', $variables);
}
/**
* Idea stolen from: http://api.drupal.org/comment/26824#comment-26824
*
* This will use the template file custompage.tpl.php in the same
* directory as this file.
*/
function mymodule_search_theme() {
return array ('mymodule_search_foo' =>
array('template' => 'custompage',
'arguments' => array()));
}
希望这有助于某人!