Skip to main content

Embed Html Page with Menu Display handler in Node

Recently I have done some interesting task in my project, my client wants to embed html page into drupal node. So they can show the well-designed html pages with drupal external functionalities(menus, block in the sidebar, footer). It is an 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 it 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 the menu in that node page.

So we have to provide a field to choose to disable 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 

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.