HubSpot CMS

Menu Module Starter

A starter script for quickly building HubSpot menu's using the menu() function. A tutorial explaining how this works is available on Braces.

Created by: Jon McLaren

Tags: Menus and navigation

Unverified
?

After receiving a minimum of 25 recommendations, an entry earns the "Community Approved" badge.

Please keep in mind, all entries are community created and may not be fully supported by HubSpot.

4 Recommendations

View on:

GitHub

HTML + HUBL
          
            {%- macro render_link_item(link,depth)-%}
  {%- if link != [] && link.label -%}
    <li class="hs-menu-item hs-menu-depth-{{depth}} {{'hs-item-has-children' if link.children}}" aria-role="none" {{'aria-haspopup="true"' if link.children}}>
      <a href="{{link.url if link.url else '#'}}" aria-role="menuitem">{{link.label}}</a>
      {%- if link.children -%}
      <ul class="hs-menu-children-wrapper" aria-role="menu">
        {% set depth = depth + 1%}
        {%- for sublink in link.children -%}
        {{render_link_item(sublink,depth)}}
        {%- endfor -%}
      </ul>
      {%- endif -%}
    </li>
  {%- endif -%}
{%- endmacro -%}
  <nav class="sc-site-header__menu sc-site-header__menu--{{ module.menu_field }} hs-menu-wrapper active-branch flyouts hs-menu-flow-horizontal" aria-label="{{menu_name}} menu">
      
      {% set menu = menu(module.menu_field , "site_root").children %}
      <ul aria-role="menubar">
       {% for link in menu %}
        {{render_link_item(link,1)}}
       {% endfor %}
      </ul>
  </nav>

          
        
CSS
          
            /* This module gets most of it's styles from the HubSpot boilerplate css to start, add your own styles if necessary. */

          
        
JS
          
            // No JS needed

          
        
Have Questions?

Ask technical questions in Slack.

HubSpot Developer Slack

Not a member yet? - join here
READ ME (VIEW IN GITHUB)

HubSpot


This is a basic menu module to use as a starter for your own menus using the HubSpot menu() function. Intentionally it does not have any CSS of it's own. When popped into a page using HubSpot's boilerplate css however it will render just like the HubSpot menu tag menu's do.

You can then easily modify the html to fit your specific needs to build mega menus or other advanced features.

 
4 Recommendations

Jon McLaren

@spingroup

Web Developer, HubSpot Development Specialist

View Jon McLaren’s Gallery (4 Entries)

Contribute to the Gallery!

We bet you’ve coded some amazing stuff. Showcase them and help the community grow.

Contribute

Other Open Source Projects

Browse all other open source projects

CrankShaft Framework

A modern framework for accelerating build times on the HubSpot CMS. Based on a modified Bootstrap 4 framework.

Lead developers: Jon McLaren

Developer Chrome Extension

Chrome/Chromium extension for HubSpot CMS Developers that adds a developer menu, dark theme and useful shortcuts to commonly used HubSpot query parameters, resources, and tools for making HubSpot Development easier and more enjoyable.

Lead developers: Jon McLaren , William Spiro , Gonzalo Torreras

VS Code HubL Language Extension

This extension enables super fast local development of CMS pages, and is a great compliment to using the new local HubL server. It contains comprehensive HubL tag, function, filter and expression test auto-complete snippets, as well as their documentation.

Lead developers: William Spiro

Not coding on HubSpot CMS yet?

We invite you to explore why thousands of developers LOVE coding with HubSpot!

Contribute
Made with  by community members: InboundLabs.co