0

Webサイトの検索ページと検索方法を完全にオーバーライドするカスタムDrupal7モジュールを作成しています。これが私がこれまでに持っているものです:

/**
 * 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 に答える