Magento 2 – Find ‘Name’ for a ReferenceBlock

layoutmagento2xml

I want to remove some blocks from my page. Say for example that I want to remove the container for the logo.

Then I create /app/design/frontend/MYVENDORNAME/MYTHEMENAME/Magento_Theme/layout/default.xml with the following code:

<page layout="3columns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <referenceBlock name="logo" remove="true"/>
</page>

In this case I managed to find out the name (name="logo") of this reference block by searching through the files in the Base Theme.

The question is: Is there a better way to find out the names of blocks. I figure there must be a list of all names used in the XMl files in Magento? Or some kind of reference?

Say for example that I would like to remove the menu (<div class="sections nav-sections">...</div>). How do I find out the name of that

Best Answer

There are a couple of ways to do this:

  1. Guess
  2. Review Layout for Base, Blank and Luma Themes
  3. Perform IDE Searches for Class and ID Names
  4. Enable 'Enabled Template Path Hints for Storefront' and 'Add Block Names to Hints'.

You can enable path hints and block hints by logging into the admin interface and going to:

Stores > Configuration > Advanced > Developer > Debug

Unfortunately, there's still no surefire way to find these easily, as far as I know. Though it looks like the guys working on the core are on to it:

https://github.com/magento/magento2/issues/571