Magento – Positioning a block in product detail, magento 2

blockslayoutmagento2position;

I've been looking for positioning a block (it's a banner image). In the product details section, my layout is set in '3columns', I want to insert it in top of the three columns, inside of the container div (its class is "columns")

I've created a static block, then a widget to positioning; and the positions available aren't the one i'm looking for.

If you want to know, I would like to change the structure of the 3 columns + my block

Thanks!

Best Answer

You can select "Before Main Columns" container and render your CMS block before div.columns if you are using widget to add it to the product details page.

enter image description here

Containers are defined in Magento/Theme/view/base/page_layout/empty.xml:

<container name="columns.top" label="Before Main Columns"/>
<container name="columns" htmlTag="div" htmlClass="columns">

The missing label of columns container excludes it from the dropdown with containers in the admin area. This is some kind of magento core team restrictions I think to place CMS blocks in any containers (there is a lot of structural blocks).

Anyway if you want to place that CMS block inside the .columns div you can create layout xml file in your theme and add the block:

Path: app/design/frontend/Vendor/theme/Magento_Catalog/layout/catalog_product_view.xml

<referenceContainer name="columns">
    <block class="Magento\Cms\Block\Block" name="banner" before="-">
        <arguments>
            <argument name="block_id" xsi:type="string">banner</argument>
        </arguments>
    </block>
</referenceContainer>
Related Topic