Since Magento itself is too vast not only because of its features but also because of heavy number of files within it, it is really difficult to find which file is being used for what purpose and where that file is really located.
Front End:
Magento has provided a feature in its configuration section in admin that allows us to enable template path hints. If we enable it, it will shows the file pathand block names.
To enable it:
1. Login to admin.
2. Go to System->Configuration.
3. Select a website from and click Developer tab in left.
4. In the Debug section, select Yes for Template Path Hints & Add Block Names to Hints.
5. Save configuration and refresh the front end page you will have some red blocks to indicate what files files are used in which block along with Block (class names) used.
Magento Template Path Hints Without Changing in Admin:
But enabling and disabling it from back end is boring in time to time. So I thought why not just enable the hints with some values passed via URL like http://www.mymagentosite.com/?template_hint=true or something like this. I searched where actually Magento handles this and found at app/code/core/Mage/Core/Block/Template.php. There is a method called getShowTemplateHints() at around line number 176 which handles it. The function originally looks like this:
public function getShowTemplateHints()
{
if (is_null(self::$_showTemplateHints)) {
self::$_showTemplateHints = Mage::getStoreConfig('dev/debug/template_hints')
&& Mage::helper('core')->isDevAllowed();
self::$_showTemplateHintsBlocks = Mage::getStoreConfig('dev/debug/template_hints_blocks')
&& Mage::helper('core')->isDevAllowed();
}
return self::$_showTemplateHints;
}
So the two static members (self::$_showTemplateHints & self::$_showTemplateHintsBlocks) of the class are to set to handle them. So I modified it to be something like this:
public function getShowTemplateHints()
{
if (is_null(self::$_showTemplateHints)) {
self::$_showTemplateHints = Mage::getStoreConfig('dev/debug/template_hints')
&& Mage::helper('core')->isDevAllowed();
self::$_showTemplateHintsBlocks = Mage::getStoreConfig('dev/debug/template_hints_blocks')
&& Mage::helper('core')->isDevAllowed();
}
// overwrite the template hit
$th = Mage::app()->getRequest()->getParam('th', false);
$token = Mage::app()->getRequest()->getParam('token', false);
if($th == 1 && $token == 'PHP'){
self::$_showTemplateHints = true; // for template path
self::$_showTemplateHintsBlocks = true; // block names
}
return self::$_showTemplateHints;
}
I have used two variables for security. Now if ‘th’ and ‘token’ are set with specific values then both of the static members are set to true and hence the templates will be now visible. Now if you hit something like this in your browser http://www.mymagentosite.com/?th=1&token=PHP you can see template hints and added Block Names. I found this quite handy rather than going to admin and enable/disable.
Admin:
For admin, there is no direct feature, so there is a trick direcly modifying the database table and values. This I had found in the internet. You need to add two rows in the table ‘core_config_data’ as follows for the first time:
INSERT INTO core_config_data (scope, scope_id, path, value) VALUES
('default', 0, 'dev/debug/template_hints', 1),
('default', 0, 'dev/debug/template_hints_blocks', 1);
If you have already those rows then you just need to update the ‘value’ field with 1 to enable and 0 to disable.
Disable:
UPDATE core_config_data SET value=0 WHERE scope='default' AND scope_id = 0 AND path ='dev/debug/template_hints'
Enable it again:
UPDATE core_config_data SET value=1 WHERE scope='default' AND scope_id = 0 AND path ='dev/debug/template_hints'
Hope this will help
.