1

I can see blocks on pages, their classes and structure and guess where they are added and what their name is - what is the best way to do this?

Is this what path hints is made for? Is there any other way even if it requires familiarity?

3

you can either edit the template that renders the block and add this at the top of it

echo $this->getName();

But this may not always help you.
You can enable the template path hints, then search in the layout files for something that matches the template name and the block type.

| improve this answer | |
  • What do you do when you want to remove a block? – LM_Fielding Jun 9 '16 at 12:53
  • 1
    find the block using the method explained above then remove it from the layout file using this approach: magento.stackexchange.com/q/80425/146 – Marius Jun 9 '16 at 12:55
  • No, no. I know that, I'm asking which method you prefer? And can you confirm that <referenceBlock name="name" remove="true"/> will remove the block regardless of its containers if the remove command is placed straight inside <body></body? – LM_Fielding Jun 9 '16 at 13:09
  • Yes ` remove="true"` will remove the block regardless of it's containers. – Marius Jun 9 '16 at 13:17
  • Marius, one more question. Would there be any way at all to output on the page all the relevant update handles that could apply? – LM_Fielding Jun 9 '16 at 13:35
1

Magento has a highlight mechanism in System Configuration to find the template path and also show you the block name

To turn on template path hints in Magento:

1- Log into the magento back-end admin

2- Go to System -> Configuration in the main menu

3- Go to Developer on the bottom left under ADVANCED

4- Switch to the store view on the top left to your current website or store view.

5- Under the Debug tab of the same Developer config page you will see a new option appear that will allow you to turn on/off template path hints.

Remember to clear your cache.

enter image description here

Using template path hints to see if Sweet Tooth is integrated properly

enter image description here

To remove a block from layout you can add code below in

frontend/<your_theme>/<theme_package>/layout/local.xml

<?xml version="1.0"?>
<layout>
    <default>
        <remove name="block_name" />
    </default>
</layout>
| improve this answer | |
  • This isnt the block name thats needed to remove via xml, Magentos trolled us with this – Bobadevv Jun 9 '16 at 13:07
0

As mentioned above you can enable template hints either through the admin, or it's usually faster to search the codebase. For example:

If the block/container you are trying to find has a unique class or ID then I usually find it quicker just to search for those. For example if I wanted to find out which block is responsible for the nav section (<div class="sections nav-sections">) then I would search for nav-sections inside vendor/magento.

This almost instantly returns vendor/magento/theme-frontend-blank/Magento_Theme/layout/default.xml line 20 - meaning the block name is navigation.sections. I find this much faster than enabling template hints.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.