Home
Wiki
Home
Wiki
  1. Categories
  • Back to home
  • 1. Themes
  • Vs Code
    • Getting Started
  • Kitchenware
    • 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
  • Noir
    • 0. Introduction
    • 6. FAQ
    • 1. Structure
      • _Overview
      • LayoutA.liquid
      • ComponentsList.liquid
      • Metas.liquid
      • CssVariables.liquid
      • Json.liquid
      • GoogleTagManager.liquid
      • StagingButton.liquid
    • 2. Components
      • _Overview
      • Announcement
      • BannerCarousel
      • BlogCategoryList
      • BlogHighlights
      • BlogList
      • BrandList
      • Breadcrumb
      • Cart
      • CategoriesList
      • ChangePassword
      • Checkout
      • CookieManager
      • CustomTable
      • Faq
      • FilterList
      • Footer
      • ForgotPassword
      • Form
      • IconBlock
      • Invitation
      • LastVisitedProducts
      • Login
      • Map
      • NavBar
      • Offer
      • ProductAttachments
      • ProductAttributes
      • ProductComparison
      • ProductDocumentation
      • ProductMixList
      • ProductsBlock
      • ProductsCarousel
      • ProductSingle
      • Profile
      • Quote
      • Register
      • RelatedProducts
      • SingleBlog
      • Stores
      • TextWithImage
      • ThankYouPage
      • TopBar
      • Wishlist
    • 3. Reusables
      • _Overview
      • Addresses
      • AddressForm
      • AnnouncementModal
      • BackToTop
      • BillingRetail
      • BlogPostingStructuredData
      • BrandListStructuredData
      • CollectionStructuredData
      • Company
      • General
      • GroupChildrenTable
      • Login
      • LoginModal
      • MonthlyTransactions
      • Offers
      • Orders
      • Payment
      • ProductAttachments
      • ProductAttributes
      • ProductAvailabilityAction
      • ProductComparisonButton
      • ProductComparisonFloatingButton
      • ProductGridItem
      • ProductGridItemClassic
      • ProductListItem
      • ProductModal
      • ProductStructuredData
      • ProfileInfo
      • PromptModal
      • Quotes
      • Register
      • Services
      • Shipping
      • ShoppingLists
      • ShoppingListsButton
      • ShoppingListsNavbar
      • StoresStructuredData
      • Toast
      • Transactions
      • Users
      • VariantContent
      • VariantContentClassic
      • WishlistButton
    • 4. Assets
      • Fonts
      • Images
      • Templates
      • Javascript
        • _Overview
        • theme.js
      • Css - Scss
        • _Overview
        • ThemeClasses
    • 5. SDK
      • _Overview
      • LiquidGlobals
      • ServicesSDK
  1. Categories

_findCategoryTreeByAlias

How to Use _findCategoryTreeByAlias Method#

The _findCategoryTreeByAlias method retrieves the category tree based on the current URL path or alias. This method is particularly useful for dynamically loading category trees in a web application where the URL structure corresponds to different categories. It handles complex scenarios like subdomain paths and utilizes other category-related methods to fetch the relevant data.

Usage Steps:#

1.
Trigger the Method:
This method automatically extracts the category alias from the URL path. You do not need to provide any parameters. Simply call the method when you need to retrieve the category tree based on the current URL.
2.
Define a Callback Function:
The callback function is passed as a parameter. This function will be executed once the category tree is retrieved. The retrieved category tree data will be passed as an argument to this function.
3.
Handle Retrieved Category Tree:
Inside your callback function, you can process the retrieved category tree. This might involve displaying the category structure on the UI, using it for navigation, or performing other actions based on the category hierarchy.

Example:#

In this example:
The handleCategoryTree function will be executed once the category tree is retrieved, allowing you to process the data as needed.

Common Use Cases:#

1.
Dynamic Category Pages:
Use this method to load and display the correct category tree on dynamic category pages based on the current URL structure.
2.
SEO-Friendly URLs:
In applications where the category structure is embedded in the URL, this method allows you to dynamically fetch and display categories without hardcoding the category tree.
3.
Optimized Data Retrieval:
The method makes use of caching and existing category retrieval methods, ensuring efficient data fetching while adapting to complex URL structures.

Notes:#

URL Path Extraction: The alias is the second segment of the URL path: for /categories/kitchen it is kitchen. When the store is served under a sub-path (stored in the _domainpath cookie), that segment is removed first.
No alias in the URL: If the path has no second segment, the callback receives the entire category tree.
Unknown alias: If the second segment does not match any category alias, there is no fallback. The method fails with a TypeError while reading the category id, and the callback is never called. On pages where the URL may not name a category, check the alias with _findCategoryByAlias first, or call _findCategoryTreeById(null, callback) to get the full tree.
Asynchronous Process: Since the method involves fetching category data based on the alias, the callback function will be executed asynchronously once the data is retrieved.
This method provides a powerful way to dynamically load and manage category trees based on the current URL, making it ideal for applications with complex routing or SEO-friendly URL structures.
Modified at 2026-10-07 12:02:07
Previous
_findCategoryByAlias
Next
_getCategoryContent
Built with