I want to display categories tree on frontend like admin default categories tree.
Need to display category tree structure in my custom module and content area for frontend side.
Any Help would be appreciated.
Thanks.
category-treefrontendmagento2
I want to display categories tree on frontend like admin default categories tree.
Need to display category tree structure in my custom module and content area for frontend side.
Any Help would be appreciated.
Thanks.
Best Answer
1) go to "app" from root directory of Magento 2 and create new directory code. Then create two more directories in app/code, Namespace and Module Name. The final directory will look like this: app/code/Demo/CategoryTree.
Demo as Namespace and CategoryTree as module name.
2) create "module.xml" file in app/code/Demo/CategoryTree/etc and paste below code into the file:
3) create "route.xml" file in app/code/Demo/CategoryTree/etc/frontend and paste below code into the file:
4) create "registration.php" file in app/code/Demo/CategoryTree and paste below code in file:
5) create "Index.php" file in app/code/Demo/CategoryTree/Controller/Index and paste below code into the file:
6) create "categorytree_index_index.xml" file in app/code/Demo/CategoryTree/view/frontend/layout and paste below code into the file:
7) copy from vendor/magento/module-catalog/view/adminhtml/templates/catalog/category/tree.phtml to app/code/Demo/CategoryTree/view/frontend/templates/catalog/category
8) create "requirejs-config.js" file in app/code/Demo/CategoryTree/view/frontend and paste below code into the file:
9) Run below commands in the root directory:
10) run url like this "http://local-magento.com/categorytree/index/index" so you will get output like below.