Legacy Knowledge Base
Published Jul. 2, 2025

How to access a custom navigation menu in theme

Written By

Sarah Marley

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

Issue

  • DXP 7.0+ provides capability to create navigation menus from the UI (production menus). However, after creating one navigation menu, I am trying to refer the menu items inside theme. I know the default main nav can be accessed in the theme (as navItems in init.ftl), so I wonder if there are any service calls that can be used to get menu items from the new created navigation menu? ( ie. something similar as layoutService = serviceLocator.findService("com.liferay.portal.kernel.service.LayoutLocalService") 
    I think it should have a way to reference it like other objects (users, articles etc.) 

Environment

  • Liferay DXP 7.0+

Resolution

  • The most important thing I need is how to reference it inside a theme, not an ADT, that is, I need to get the new menu object in the theme. Is there a local service to call to get it?
    If you are referring to local services that can be used to access the site navigation menu, you would need the following:
    If you know the exact values in the database, you might invoke these services as follows:
    <#assign ddmTemplateLocalService = serviceLocator.findService("com.liferay.dynamic.data.mapping.service.DDMTemplateLocalService")>
    <#assign template = ddmTemplateLocalService.fetchDDMTemplate(...)>
    <#assign siteNavigationMenuLocalService = serviceLocator.findService("com.liferay.site.navigation.service.SiteNavigationMenuLocalService")>
    <#assign navigationMenu = siteNavigationMenuLocalService.fetchSiteNavigationMenu(...)>
    However, a lot of the API that converts a SiteNavigationMenu into a list of NavItem objects is not public, so even with the API, it's not possible to do everything from the theme.
    Instead of doing everything from the theme, developers are expected to create an Application Display Template (ADT) for Navigation Menu Template. Inside of the ADT, the entries object will contain a list of NavItem objects, and you can operate on that list in the same way as you would have done in a theme during past Liferay releases.
    Once you've created an ADT, you can use the liferay-site-navigation:navigation-menu tag library from inside the theme in order to run the code inside the ADT. As an example, you would have something like the following (consult the tag library documentation for additional information on the fields that aren't directly related to the ADT or the navigation menu):
    <@liferay_site_navigation["navigation-menu"]
    ddmTemplateGroupId=template.groupId
    ddmTemplateKey=template.templateKey
    displayDepth=1
    expandedLevels="auto"
    rootItemType="absolute"
    rootItemLevel=0
    siteNavigationMenuId=navigationMenu.siteNavigationMenuId />
  •  The Westeros Bank Theme is also an example of modifying the navigation menu inside the theme. This uses the macro to embed the portlet: https://github.com/liferay/liferay-portal/blob/7.2.x/modules/apps/frontend-theme-westeros-bank/frontend-theme-westeros-bank/src/templates/navigation.ftl
  • See also the example mentioned in Liferay DXP FreeMarker Macros (Reference Examples).
Did this article resolve your issue ?

Legacy Knowledge Base