0

我正在编写一个自定义 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 的内置模板系统来呈现结果?

4

2 回答 2

2

你必须使用drupal的内置函数。我希望你正在寻找这样的东西http://api.drupal.org/api/drupal/includes!common.inc/function/drupal_render/7

于 2013-03-26T10:50:08.357 回答
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()));
}

希望这对某人有帮助!

于 2013-03-27T14:19:30.567 回答