Home >How to enable Template Path Hints in Magento 1 and Magento 2

How to enable Template Path Hints in Magento 1 and Magento 2

Template Path Hints are an useful tool that help us identify each blocks added to each pages. Which means that if you want to make a change in any page, you needed to first know from where that html code is generated.

And anyone, who has developed a theme in Magento, knows how helpful Template/Block Hint are. So this detailed article will guide you how to enable Template Path Hints in Magento 1 and Magento 2.

Magento 1

To enable Template Path Hints in Magento 1, please follow the steps.

Turn on Template Path Hints in Admin.

Please go to Dashboard -> System -> Configuration, choose scope level: store view which you want to enable.

In tab Advanced -> click Developer:

  • Allowed IPs: fill your IP
  • Template Path Hints: choose Yes
  • Add Block Names to Hints: choose Yes

Turn on Template Path Hints in source code.

Open file as editor and edit: app\code\core\Mage\Core\Block\Template.php.

Set 2 variable: $_showTemplateHints and $_showTemplateHintBlocks to 1.

protected static $_showTemplateHints=1;
protected static $_showTemplateHintsBlocks=1;

Save file and remember to plush the cache.

Magento 2

Turn on Magento 2 Template Hints in Admin.

Same as Magento 1, in Magento 2 you go to admin Dashboard -> Stores -> Configuration and choose store view which you want to enable.

magento-2-template-hints

In tab Advanced -> click Developer and following the same step as in Magento 1.

magento-2-template-hints-debug

Or you can set scoped by Default config to enable Path Hints in Backend.

magento-2-template-hints-for-admin

Turn on Magento 2 Template Hints in source code.

Open file as editor and edit:

Vendor\magento\module-developer\Model\TemplateEngine\Plugin\DebugHints.php

Find function afterCreate, close condition “if” in this function. Save file.

public function afterCreate(
        TemplateEngineFactory $subject,
        TemplateEngineInterface $invocationResult
    ) {
        $storeCode = $this->storeManager->getStore()->getCode();
        // if ($this->scopeConfig->getValue($this->debugHintsPath, ScopeInterface::SCOPE_STORE, $storeCode)
        //     && $this->devHelper->isDevAllowed()) {
            $showBlockHints = $this->scopeConfig->getValue(
                self::XML_PATH_DEBUG_TEMPLATE_HINTS_BLOCKS,
                ScopeInterface::SCOPE_STORE,
                $storeCode
            );
            return $this->debugHintsFactory->create([
                'subject' => $invocationResult,
                'showBlockHints' => $showBlockHints,
            ]);
        //}
        return $invocationResult;
    }

If you want to enable Block Names class, you can change variable $showBlockHints to 1. Remember to flush the cache after finishing all above steps.

Hope the article help you to enable Magento 1 and Magento 2 template hints in your development of modules.

< Previous Post
Next Post >
+ posts