Magento – Is it possible to remove elements in a page layout in Magento2

blockscontainersmagento-2.0magento2page-layouts

When I read the documentation on page-layouts (http://devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/layout-types.html#layout-types-page) I see that the following instructions in this XML document are allowed:

  • <container>
  • <referenceContainer>
  • <move>
  • <update>

Since <referenceBlock name="block.name" remove="true" /> isn't one of the allowed instructions how can I remove a certain element in a specific page layout?

What I want for the top-categories is a whole other page design. I don't need certain containers and blocks for this design. For these categories I only want to show child categories and not the products.

The thing I've done now is, added the following lines in my page layout:
(in design\frontend\Vendor\Name-of-theme\Magento_Theme\page_layout\catalog-blocks.xml)

<move element="category.image" destination="delete"></move>
<move element="category.description" destination="delete"></move>
<move element="category.products" destination="delete"></move>
<move element="page.main.title" destination="delete"></move>

In the design\frontend\Vendor\Name-of-theme\Magento_Theme\layouts.xml I addded:

<layout id="catalog-blocks">
    <label translate="true">Catalog Blocks</label>
</layout>

I gave all the top-categories this catalog-blocks page layout in the admin.

Then in the main layout (design\frontend\Vendor\Name-of-theme\Magento_Theme\layout\default.xml) I added:

<referenceBlock name="delete" remove="true" />

So the whole delete block will be deleted, with all the things I moved here, in the page layout. This works well! It achieves exactly what I want but the whole thing seems to me a little hackish.

Is this considered being a good practice? If not, what would be a good alternative?

Edit 1: Changed the remove-tag in my question with the right one to avoid confusion.

Edit 2: Some more information about the files and file-locations.

Best Answer

What about:

  • creating a new container (instead of a block)
  • move your blocks to the container
  • remove the container

Something like this:

<container name="delete" htmlTag="div" htmlClass="delete"/>

<move element="category.image" destination="delete"></move>
<move element="category.description" destination="delete"></move>
<move element="category.products" destination="delete"></move>
<move element="page.main.title" destination="delete"></move>

<referenceContainer name="delete" remove="true" />