从模块渲染没有主题的节点(无主题编辑)

时间:2012-06-29 14:52:31

标签: drupal module drupal-6 drupal-modules

我有一个模块,用于创建几个页面节点(在.install中完成)。这工作正常。问题是这些节点包含xml,json,jsonp内容,所以我希望能够在没有主题,没有标题,没有页脚,没有样式,只是node->内容的情况下呈现它们。 这个模块将与其他几个Drupal站点共享,所以我不能用主题开发这个,我不希望任何人创建或修改模板。

有没有办法使用模块内的钩子,.module?基本上检测节点标题或节点别名(或某些内容),然后阻止主题呈现并仅呈现内容。我会知道节点的标题和别名,因为我在.install中创建它们。

我还想正确修改标题,告诉我们返回的是xml,json等。

提前致谢。

1 个答案:

答案 0 :(得分:0)

通常情况下,我会采取另一种方式。我通过hook_menu()菜单路由器项而不是节点内容来定义内容,因为它很少直接用户可编辑。如果有大量处理,您可以将其与.module分开,并将其作为file包含在每个项目中。

/**
 * Implementation of hook_menu().
 */
function MODULE_menu() {
  $items = array();

  $items['example/json'] = array(
    'title'            => 'JSON example',
    'page callback'    => '_MODULE_json',
    'access arguments' => array('access content'),
    'type'             => MENU_CALLBACK,
  );
  $items['example/xml'] = array(
    'title'            => 'XML example',
    'page callback'    => '_MODULE_xml',
    'access arguments' => array('access content'),
    'type'             => MENU_CALLBACK,
  );

  return $items;
}

/**
 * JSON example.
 */
function _MODULE_json($string = '') {
  $data = array();
  $data['something']    = 0;
  $data['anotherthing'] = 1;
  drupal_json($data);
}

/**
 * XML example. No idea if this actually produces valid XML,
 * but you get the idea.
 */
function _MODULE_xml($string = '') {
  $data = array();
  $data['different'] = 2;
  $data['evenmore']  = 3;

  // Build XML
  $output  = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
  $output .= "<data>\n";
  $output .= format_xml_elements($data);
  $output .= "</data>\n";

  // We are returning XML, so tell the browser.
  drupal_set_header('Content-Type: application/xml');
  echo $output;
}