Skip to main content
menu

Embed Html Page with Menu Display handler in Node

Recently i have done some interesting task in my project, my client want to embed html page into drupal node. So they can show the well designed html pages with drupal external functionalities(menus, block in sidebar, footer). It is a easy one to develop it. I have done it in the following ways,

  1. Created new content type (html_page)
  2. Added Iframe field to embed html pages (iframe module provide the field option)
  3. Removed Title, body field from the node display option, so that i can show only the html embed pages in the node view

This has been working well and client also very happy with that solutions, but after that they want some other features in that, We have user menu and main menu in top the html page node, they want a flag option to choose to show either user menu or main menu. If we have an option then they can simply disable any one of menu in that node page.

So we have to provide a field to choose to disable the both user menu and main menu. I have added a new select field with user menu and main menu’s class as value for the select field,

kf_user_nav_out|User Menu 

section-main-menu|Main menu 
text

So the menu’s class name would be the value of the option. After that, we have to do the main functionality in hook_node_view(), just place the following code in your hook_node_view(),

if ($node->type == 'html_page') {
    if (isset($node->field_disable_menus[LANGUAGE_NONE])) {
      foreach ($node->field_disable_menus[LANGUAGE_NONE] as $value) {
        $js = 'jQuery(document).ready(function() {
          jQuery(".' . $value['value'] . '").hide();
        });';
        drupal_add_js($js, 'inline');
      }
    }
  }

It will disabled the marked menu in the html page node page. We are just hide the menus from jquery so originally the menus will be rendering as normal. If you know any better solutions just share it on comments.

Add new comment

The content of this field is kept private and will not be shown publicly.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.