How to retrieve a list of categories and n childs on the front end? (only categories with products)

Hi,

I need to build a mega menu in the front end and would like to know if there’s a way to retireve the category tree (only categories with products in it).

Also, is there a way to create custom category tree?

@rafaelmarques you can fetched the collection into megamenu by adding follow code :

{%- for link in linklists.categories.links -%}
          - {% render 'card-collection', card_collection: link.object, media_aspect_ratio: section.settings.image_ratio, columns: 3 %}
          
      {%- endfor -%}

Hi @Ujjaval , thanks for replying. I might have left out some info in my question. I’m not using the LIQUID template, I’m working on a custom store front that integrates everything via graphql api. So I’d need to get the category tree from there. Do you know if it’s possible?