我有一个drupal模块,其函数返回附件text/plain,
function mymodule_menu() {
$items = array();
$items[MY_PATH] = array(
'title' => 'some page',
'page callback' => 'myfunction',
'type' => MENU_CALLBACK,
);
}
function myfunction()
{
drupal_set_header('Content-Type: text/plain');
return "some text";
}
Run Code Online (Sandbox Code Playgroud)
但它返回page.tpl.php模板中的页面,但是我希望它没有模板化,我如何覆盖主题以使其返回纯文本?
谢谢,
汤姆
这将返回纯文本
function myfunction() {
drupal_set_header('Content-Type: text/plain');
print "some text";
exit(0);
}
Run Code Online (Sandbox Code Playgroud)
小智 7
或者,您可以使用菜单回调定义中的"传递回调"设置.现在你的页面回调函数将通过一个只打印和退出的自定义函数运行,而不是调用drupal_deliver_html_page(),这是输出所有典型主题标记等的内容.
function mymodule_menu() {
$items = array();
$items['MY_PATH'] = array(
'title' => 'some page',
'page callback' => 'myfunction',
'type' => MENU_CALLBACK,
'delivery callback' => 'mymodule_deliver_page',
);
return $items;
}
function mymodule_deliver_page($page_callback_result) {
print $page_callback_result;
exit(0);
}
Run Code Online (Sandbox Code Playgroud)
你的模块可以定义模板文件(参考):
<?php
function mymodul_preprocess_page(&$variables) {
foreach ($variables['template_files'] as $file) {
$template_files[] = $file;
if ($file == 'page-node') {
$template_files[] = 'page-'. $variables['node']->type;
}
}
$variables['template_files'] = $template_files;
}
?>
Run Code Online (Sandbox Code Playgroud)
通过为相关页面创建一个新的 .tpl.php 文件。例如
页面模块.tpl.php
page-module.tpl.php 只需要一个简单的页面,例如
<?php
print $content;
?>
Run Code Online (Sandbox Code Playgroud)