Drupal 包含的文件显示在模板外部
我正在尝试为Drupal开发一个模块,我是个新手 除了包含的文件外,下面的代码运行良好。包含文件的内容将显示在模板外部,而其余内容将正确显示在模板内部。为什么会发生这种情况,如何解决Drupal 包含的文件显示在模板外部,drupal,include,Drupal,Include,我正在尝试为Drupal开发一个模块,我是个新手 除了包含的文件外,下面的代码运行良好。包含文件的内容将显示在模板外部,而其余内容将正确显示在模板内部。为什么会发生这种情况,如何解决 drupal_add_css(drupal_get_path('module', 'helloworld') . '/helloworld.css', array('group' => CSS_DEFAULT, 'every_page' => TRUE)); function hellowor
drupal_add_css(drupal_get_path('module', 'helloworld') . '/helloworld.css', array('group' => CSS_DEFAULT, 'every_page' => TRUE));
function helloworld_menu(){
$items = array();
$items['helloworld'] = array(
'title' => t('Hello world'),
'page callback' => 'helloworld_output',
'access arguments' => array('access content'),
);
return $items;
}
function helloworld_display(){
include_once ( dirname(__FILE__) . '/helloworld.display.php');
}
/*
* Display output
*/
function helloworld_output() {
header('Content-type: text/plain; charset=UTF-8');
header('Content-Disposition: inline');
$output = "<div id='hw_wrapper'>";
$output .= helloworld_display();
$output .= 'hej';
$output .= "</div>";
return $output;
}
试试这个代码
MYMODULE.module
theme/test-page.tpl.php
我宁愿使用以下代码
function helloworld_output() {
drupal_add_http_header('Content-type', 'text/plain; charset=UTF-8');
drupal_add_http_header('Content-Disposition', 'inline');
return array(
'#prefix' => '<div id="hw_wrapper">',
'#suffix' => '</div>',
'#theme' => 'helloworld_mypage',
'#attached' => array(
'css' => drupal_get_path('module', 'helloworld') . '/helloworld.css',
),
);
}
如果对drupal\u add\u http\u头进行了一次调用,则可以用附加数组中的一个项替换它,如下代码所示
function helloworld_output() {
drupal_add_http_header('Content-type', 'text/plain; charset=UTF-8');
drupal_add_http_header('Content-Disposition', 'inline');
return array(
'#prefix' => '<div id="hw_wrapper">',
'#suffix' => '</div>',
'#theme' => 'helloworld_mypage',
'#attached' => array(
'css' => drupal_get_path('module', 'helloworld') . '/helloworld.css',
),
);
}
有关更多信息,请参阅
helloworld.display.php文件的内容是什么
function helloworld_init() {
drupal_add_css(drupal_get_path('module', 'helloworld') . '/helloworld.css', array('group' => CSS_DEFAULT, 'every_page' => TRUE));
}
function helloworld_menu(){
$items = array();
$items['helloworld'] = array(
'title' => t('Hello world'),
'page callback' => 'helloworld_output',
'access arguments' => array('access content'),
);
return $items;
}
/*
* Display output
*/
function helloworld_output() {
drupal_add_http_header('Content-type', 'text/plain; charset=UTF-8');
drupal_add_http_header('Content-Disposition', 'inline');
return array(
'#prefix' => '<div id="hw_wrapper">',
'#suffix' => '</div>',
'#theme' => 'helloworld_mypage',
);
}
function helloworld_theme() {
return array(
'helloworld_mypage' => array(
'variables' => array(),
'template' => 'helloworld-mypage',
),
);
}
function helloworld_output() {
drupal_add_http_header('Content-type', 'text/plain; charset=UTF-8');
drupal_add_http_header('Content-Disposition', 'inline');
return array(
'#prefix' => '<div id="hw_wrapper">',
'#suffix' => '</div>',
'#theme' => 'helloworld_mypage',
'#attached' => array(
'css' => drupal_get_path('module', 'helloworld') . '/helloworld.css',
),
);
}
function helloworld_output() {
return array(
'#prefix' => '<div id="hw_wrapper">',
'#suffix' => '</div>',
'#theme' => 'helloworld_mypage',
'#attached' => array(
'css' => drupal_get_path('module', 'helloworld') . '/helloworld.css',
'drupal_add_http_header' => array('Content-type', 'text/plain; charset=UTF-8'),
),
);
}