【问题标题】:Static HTML page in custom Drupal Module [closed]自定义 Drupal 模块中的静态 HTML 页面 [关闭]
【发布时间】:2014-11-05 21:16:24
【问题描述】:

我需要创建一个在特定菜单项上生成静态 HTML 页面的自定义模块。我知道如何使用菜单挂钩创建菜单项,但我将如何让模块在该菜单页面上生成静态 html?

基本上,我创建了一个静态 HTML 站点,需要将其包含到模块中。然后我将模块发送给其他人安装在他们的网站上。

我还必须包含所有图像、css 和 javascript。它还需要在当前主题之外存在,因为它也具有不同的外观和感觉。

【问题讨论】:

    标签: html drupal drupal-7


    【解决方案1】:

    像往常一样创建 .html、.css 和 .js 文件(但是,不要在 .html 文件中包含 <html><head><body> 标签,因为您的模块已加载)。您定义的任何 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;
    }
    

    【讨论】:

    • 谢谢你,这让我接近了我所需要的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多