Magento development requires a lot of effort, especially when working with templates. Thus when you create a new theme in Magento 2 or override existing theme files, you need to know the exact location of the templates.
Since endless searching in the code won't suffice, you need some tips — Magento 2 template hints. So, in this article, you'll learn how to enable the Magento template path hints for admin and storefront in two different ways.
Post Contents [hide]
Before we get to the methods of enabling template path hints in Magento, let's define what they are first.
What are Magento 2 Template Hints?
Magento 2 template hints are the tips that help you define a .php block class or a .phtml template that corresponds to a specific page area on your Magento 2 store.
In other words, template path hints add a notation with the path of each template to help you locate the .phtml files more easily and edit them faster correspondingly. You can locate the code in the Magento file structure both on the frontend and the admin.
There are two ways to enable the template path hints in Magento. So, jump to the next sections to learn more details about each of them.
Enable Magento 2 Template Hints from the Admin Panel
The easiest way is to enable the template path hints via the admin panel.
Note: before using the template path hints we recommend disabling the Magento block and page cache.
1. Turn your Magento to the default or developer mode.
2. Go to Stores > Settings > Configuration > Advanced > Developer and unfold the Debug section.
3. Enable Magento template path hints for the storefront and/or the admin panel.
If required, you can also enable hints for the storefront with the URL parameter or add block type to template hints. Just choose Yes in the corresponding fields.
4. Move to the Developer Client Restrictions section and add the IPs you want the template path hints to be available for. Leave the field empty if you don't want to set any restrictions.
Note: the template path hints will be available only for the IPs you specify in this section.
Don't forget to Save the setting once you finish. Then reload a corresponding page to see the template paths to the corresponding PHP/PHTML files.
Enable Magento 2 Template Hints via CLI
If you prefer a programming way, you can enable the Magento 2 template path hints using CLI. To do that run the following command:
php bin/magento dev:template-hints:enable
In case you need to disable template path hints, use the below command:
php bin/magento dev:template-hints:disable
Note: unlike the previous method, you can enable or disable template path hints for Magento 2 storefront only using CLI.
The template path hints come in handy when you need to find the location of some templates in the code promptly. Choose the method that works for you and continue with your development task.
But that's not it. There are likely many more development tasks you need to learn how to cope with.