Wednesday, July 15, 2020
Home > Beginners of Magento 2 > Get Current Product & Current Category in Magento 2

Get Current Product & Current Category in Magento 2

Product and Category in Magento 2

By using below steps you can get the current product and category in Magento 2. It can be helpful for your questions.

Declare Block in Ketan_GetCatalog:

Everyone can use a block class of the module Ketan_GetCatalog and inject the object Registry of \Magento\Framework\Registry class in the constructor of the module’s block class.

app/code/Ketan/GetCatalog/Block/GetCatalog.php

Get current product object in the template phtml file:

The current product can showing the following information. And the current category comes with the information.

Now please run the file to print out the current product and category in Magento 2.

Get current category object in the template phtml file:

Spread the love

Leave a Reply

Your email address will not be published.