我需要创建一个自定义模块来生成特定菜单项上的静态HTML页面。我知道如何用菜单挂钩创建菜单项,但是如何让模块在菜单页面上生成静态html呢?
基本上,我已经创建了一个静态HTML站点,我需要包含在一个模块中。然后我将模块发送给其他人安装在他们的网站上。
我还必须包括所有的图像、css和javascript。它也需要生活在当前的主题之外,因为它也有不同的外观和感觉。
发布于 2014-11-05 22:32:34
像通常一样创建.html、.css和.js文件(但是,不要在.html文件中包含<html>、<head>或<body>标记,因为在加载模块时已经包含了这些标记)。您定义的任何CSS都将覆盖Drupal的默认CSS。
然后,您可以使用Form的item元素导入静态HTML页面。
static_page.module
/**
* Implements hook_menu().
*/
function static_page_menu() {
$items = array();
$items['staticpage'] = array(
'title' => t('My Static Page'),
'page callback' => 'drupal_get_form',
'page arguments' => array('static_page_form'),
'access arguments' => array('access content'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Implements hook_form().
*/
function static_page_form($form, &$form_state) {
// Add CSS and JS
drupal_add_css(drupal_get_path('module', 'static_page') . '/static_page.css');
drupal_add_js(drupal_get_path('module', 'static_page') .'/static_page.js');
// Import your static HTML page
$form['html'] = array(
'#type' => 'item',
'#markup' => file_get_contents(drupal_get_path('module', 'static_page') .'/static_page.html'),
);
return $form;
}如果不希望静态页面包含为站点其余部分显示的标准页眉、面包屑、侧边栏和页脚,则可以使用CSS隐藏它们。
static_page.css
#header,
#breadcrumb,
.sidebar,
#footer-wrapper {
display: none !important;
}https://stackoverflow.com/questions/26767284
复制相似问题