2012-09-17

Template and Block Path Hints by Configuration

Magento Template and Block Path Hints

So you are building a new Magento theme or customizing an existing one? Your customer loves "that one", but it should look a bit like "this one"? Well then, template and Block path hints are your friends.

Magento Template and Block Path Hints

Essentially, template and block path hints are small helpers showing the position of your blocks and templates directly on the page. Using these hints, you can see where which blocks are positioned and which templates are used to render them. This can be a great help, if you want to rearrange the site structure in the process of developing a custom theme, or if you want to change the output of a particular template and need to know which one you have to overwrite.

Enabling Template and Block Path Hints in the Backend

Enabling template and path hints in the backend is straightforward. Go to the admin area, then to System/Configuration, on the left navigation panel go to Developer (under Advanced) and set template path/block path hints to enabled. Note that this option will not be visible in the "default" store scope. You will have to switch at least to the "website" scope to see the option. Otherwise you would see the path hints in the admin area too ... Wait, this is what you wanted? Well, read on.

Enabling Template and Block Path Hints by Configuration

Sometimes it is not convenient to enable and disable path hints in the backend. Suppose you just want to switch them on for a quick check and the magento backend takes ages to load (on my machine with caching switched off it does). Or you are developing something for the backend and want to see where to place it. There is no option for path hints in the backend, so what should you do?

As always with Magento, the solution involves some configuration settings. You have to inject these settings into Magento's configuration and the most easy way to do this (and the only valid one according to Magento's development philosophy), is via the config.xml file of your module. In case you are working on a theme only, you will have to add a dummy module holding the configuration file (see Alan's tutorial for the basic module stucture). In the config.xml of your module, you should add the following section to the <config> (root) node:

<default>
    <dev>
        <debug>
            <template_hints>1</template_hints>
            <template_hints_blocks>1</template_hints_blocks>
        </debug>
    </dev>
</default>

This will enable the showing of template and path hints as a default, i.e., in all stores and in the backend. If you want to disable this, simply set a "0" instead of a "1", or delete the config entry alltogether. This will work, because changing the config does not actually change the underlying DB.

Maybe you'll notice, that in your store views template/block path hints still are not shown. In this case, some setting overwrites the default setting, e.g., you disabled hints on your website scope. This is partly why manipulating the defaults is not good practice. The other part is that you seldomly need to see path hints both in the front- and in the backend while enabling the hints makes the page, ugh, not so pretty. Therefore you should consider setting the configuration only on the store scope.

For example, in order to enable path hints in your admin and in the German store ("de"), you would then use:

<stores>
    <de>
        <dev>
         <debug>
             <template_hints>1</template_hints>
             <template_hints_blocks>1</template_hints_blocks>
         </debug>
        </dev>
    </de>
    <admin>
        <dev>
         <debug>
             <template_hints>1</template_hints>
             <template_hints_blocks>1</template_hints_blocks>
         </debug>
        </dev>
    </admin>
</stores>

No comments:

Post a Comment