HomeWiki
HomeWiki
  1. Navigation
  • Back to home
  • 1. Themes
  • Layout
    • New Layout
    • Legacy Layout
  • Components
    • Announcement
    • Banner Carousel
    • Banner With Products Carousel
    • Blog Category List
    • Blog List
    • Brand List
    • Brands Carousel
    • Breadcrumb
    • Call To Action
    • Cart
    • Categories List
    • Change Password
    • Checkout
    • Cookie Manager
    • Filter list
    • Footer
    • Forgot Password
    • Form
    • Hero Carousel
    • Icon Block
    • Invitation
    • Last Visited Products
    • Layout
    • Login
    • Map
    • Nav Bar
    • Offer
    • Product Attachments
    • Product Attributes
    • Product Documentation
    • Product Expected
    • Product Modal
    • Products Block
    • Products Carousel
    • Product Single
    • Profile
    • Quote
    • Register
    • Related Products
    • Search
    • Stores
    • Subscribe Newsletter
    • Text with Image
    • Top Bar
    • Video
  • Reusables
    • Getting Started
  • Assets
    • Getting Started
  • SDK
    • Products
      • _findProductsByCategory
      • _findProductsByIds
      • _findProductsByTitle
      • _findProductsByFilter
      • _findProductsByCriteria
      • _findProductsAndCalculate
      • _findProductsThenCalculate
      • _getProductAttributeSet
      • _setLastVisited
    • Categories
      • _findCategoryTreeById
      • _findCategoriesByIds
      • _findCategoryByAlias
      • _findCategoryTreeByAlias
      • _getCategoryContent
    • Collections
      • _getCollectionContent
      • _findCollectionsByIds
      • _findCollectionsByIdsThenCalculate
    • Brands
      • _getBrandContent
      • _findBrandsByIds
    • Cart
      • _addToCartMulti
      • _addToCart
      • _setCart
      • _clearCart
      • _setCartListener
      • _removeFromCart
      • _calculateCart
    • Checkout
      • _startCheckout
      • _updateCheckout
      • _completeCheckout
    • Shopping Lists
      • _getShoppingLists
      • _updateShoppingList
      • _createShoppingList
      • _deleteShoppingList
      • _getShoppingListByAlias
    • Navigation
      • _getFooterMenu
      • _getHeaderMenu
    • Users
      • _getUserById
    • Utils
      • _calculateCurrency
      • _getCurrencySymbol
      • _getCulture
      • _subscribeToNewsletter
      • _findUnitsByIds
  • Vs Code
    • Getting Started
  1. Navigation

_getHeaderMenu

How to Use _getHeaderMenu Method#

The _getHeaderMenu method is used to retrieve the main header menu of the application. It leverages caching and local storage to optimize performance, reducing the need for repeated API requests. This method is ideal for loading navigation menus that are frequently accessed by users.

Usage Steps:#

1.
Trigger the Method:
This method does not require any input parameters. You simply call the method to retrieve the header menu.
2.
Define a Callback Function:
The callback function is passed as a parameter. This function will be executed once the header menu is retrieved. The retrieved menu data will be passed as an argument to this function.
3.
Handle Retrieved Header Menu:
Inside your callback function, you can process the retrieved menu data. This might involve displaying the menu on the UI, rendering navigation links, or performing other actions based on the menu structure.

Example:#

In this example:
The handleHeaderMenu function will be executed once the header menu is retrieved, allowing you to process and display the menu data as needed.

Common Use Cases:#

1.
Header Navigation:
Use this method to dynamically load and display the main navigation menu in the header of your application.
2.
Optimized Menu Loading:
This method is useful for optimizing the loading of menus that are frequently accessed, ensuring a faster user experience by caching the data.
3.
Localized Menus:
If your application supports multiple languages, this method will fetch and cache the appropriate menu based on the current language setting.

Notes:#

Caching: The method caches the main header menu in memory (_cache_main_menu) and in local storage to improve performance. If the cache is available, it will be used instead of making an API call.
Language-Specific Data: The method retrieves the header menu data based on the current language setting, ensuring that users see the correct version of the menu for their language.
Asynchronous Process: Since the method may involve an API call, the callback function will be executed asynchronously once the data is retrieved.
This method is an efficient way to manage and retrieve the main header menu for your application, providing flexibility in how the menu data is utilized and displayed.
Previous
_getFooterMenu
Next
_getUserById
Built with