我需要创建一个自定义模块,以在特定菜单项上生成静态HTML页面。我知道如何使用菜单钩子创建菜单项,但是我将如何让模块在该菜单页面上生成静态html?
基本上,我创建了一个静态HTML网站,需要将其包含在模块中。然后,我将该模块发送给其他人以在其站点上安装。
我还必须包括所有图像,css和javascript。它也需要脱离当前主题,因为它的外观也不同。
创建您的.html,的CSS和.js文件就像你通常会(但不包括<html>
,<head>
或<body>
当你的模块被加载在你的HTML文件,因为这些标签就已经被包括在内)。您定义的任何CSS都会覆盖Drupal的默认CSS。
然后,您可以使用Form API的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;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句