Magento 2 – Move Block in Catalog Product View Layout

cataloglayoutmagento-2.1magento2product-view

I'm using Magento 2.1 and I just wanted to move a block in the product view layout, extending the existing layout.

My theme inherits from blank theme, and I have tried just to copy/paste what is done in magento-luma theme, and how it is explained in the official guide

(here and here)

So I just created an extending catalog_product_view.xml inside

app/design/frontend/Vendor_name/theme_name/Magento_Catalog/layout

with a similar content of what is done in luma-theme, like this

<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <move element="page.main.title" destination="product.info.main" before="-"/>
    </body>
</page>

but actually, nothing is moving.

I also tried overriding the layout, either the theme layout, as well as the module base layout, as mentioned in the official guide about overriding themes (here).

Cleared cache several times, regenerated static files, but nothing continues to happen.

What am I missing?

EDIT:

checking for erros in log files, in system.log I found this:

    [2017-08-30 13:21:48] main.INFO: Cache file with merged layout: LAYOUT_frontend_STORE1_411c931cf412fc3b1664f9d6f27c7e38e and handles default, catalog_product_view, catalog_product_view_id_1, catalog_product_view_sku_Primo%20prodotto, catalog_product_view_type_virtual: Please correct the XML data and try again.  [] []
[2017-08-30 13:21:48] main.INFO: Cache file with merged layout: LAYOUT_frontend_STORE1_40a98983867a1770682b48d9a0ad63441 and handles 1column: Please correct the XML data and try again.  [] []
[2017-08-30 13:21:48] main.CRITICAL: Broken reference: the 'catalog.compare.sidebar' element cannot be added as child to 'sidebar.additional', because the latter doesn't exist [] []
[2017-08-30 13:21:48] main.CRITICAL: Broken reference: the 'sale.reorder.sidebar' element cannot be added as child to 'sidebar.additional', because the latter doesn't exist [] []
[2017-08-30 13:21:48] main.CRITICAL: Broken reference: the 'wishlist_sidebar' element cannot be added as child to 'sidebar.additional', because the latter doesn't exist [] []
[2017-08-30 13:21:48] main.CRITICAL: Broken reference: the 'product.info.price' tries to reorder itself towards 'product.info.review', but their parents are different: 'product.info.main' and 'product.info.price' respectively. [] []
[2017-08-30 13:21:48] main.CRITICAL: Broken reference: the 'product.price.final' tries to reorder itself towards 'product.info.sku', but their parents are different: 'product.info.price' and 'product.info.stock.sku' respectively. [] []
[2017-08-30 13:21:48] main.CRITICAL: Broken reference: the 'product.info.social' tries to reorder itself towards 'product.info.overview', but their parents are different: 'product.info.extrahint' and 'product.info.main' respectively. [] []
[2017-08-30 13:21:48] main.CRITICAL: Broken reference: the 'view.addto.wishlist' tries to reorder itself towards 'view.addto.requisition', but their parents are different: 'product.info.addto' and '' respectively. [] []
[2017-08-30 13:21:48] main.CRITICAL: Broken reference: the 'bml.right.logo' tries to reorder itself towards 'product.info.addtocart.paypal', but their parents are different: 'product.info.addtocart' and '' respectively. [] []
[2017-08-30 13:21:48] main.INFO: Cache file with merged layout: LAYOUT_frontend_STORE1_46f1b068ec7ccf4878f9284dd1137afd1 and handles catalog_product_prices: Please correct the XML data and try again.  [] []
[2017-08-30 13:21:57] main.INFO: Cache file with merged layout: LAYOUT_frontend_STORE1_4c7dd4384a0ea945ae0d791fa12c5fba3 and handles review_product_listajax: Please correct the XML data and try again.  [] []
[2017-08-30 13:21:57] main.INFO: Cache file with merged layout: LAYOUT_frontend_STORE1_4c7dd4384a0ea945ae0d791fa12c5fba3 and handles review_product_listajax: Please correct the XML data and try again.  [] []

but actually, updating the catalog_product_view.xml to this

<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
         <body>
            <referenceBlock name="product.info.overview" remove="true" />
        </body>
    </page>

still does not reflect on the frontend, nor in the log files. It seems simply ignored.

I am in developer mode and disabled all cache files.

EDIT2:

comes out that the system.log errors are a not yet corrected Magento bug, and nothing important.

The other try I have done is to modify the catalog_product_view.xml in Magento/luma theme and it behaves exactly as expected.

Tried to extend another layout in my theme and no effect.

In the end I have created other two themes from scratch, one inheriting from blank and the other from luma, and the remove instruction works. But still no luck with move.

Best Answer

The block is currently at the top of product.info.main so may not be moving due to this.

Try below to move to another container:

e.g

<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
  <body>
    <move element="page.main.title" destination="content" before="-"/>
  </body>
</page>

Study vendor\magento\module-catalog\view\frontend\layout\catalog_product_view.xml to see what containers exist and what they contain.

You can then set the destination to the container you wish. To order within the container you can change the before or after argument to the name of the block you want it to be before or after or before="-" for before all or after="-" for after all.

See below for a lot more on layouts:

http://devdocs.magento.com/guides/v2.1/frontend-dev-guide/layouts/xml-instructions.html

Related Topic