blog-banner

Embed HTML Page With Menu Display Handler in Node

  • Drupal Planet
  • Embed
  • Menu

Recently I have done some interesting tasks in my project, my client wants to embed an HTML page into the 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. 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 provides 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 the client is also very happy with that solution, but after that, they want some other features in that, We have a user menu and main menu at the top of 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 menus on that node page.

So we have to provide a field to choose to disable both the user menu and the main menu. I have added a new select field with the user menu and main menu’s class as values 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 disable the marked menu on the HTML page node page. We are just hiding the menus from jquery so originally the menus will be rendering as normal. If you know any better solutions just share them in the comments.

Get awesome tech content in your inbox