Magento 2 - Move Blocks based on Design Layout Type of Product

by harri   Last Updated October 11, 2018 15:09 PM

I want to have a few layout types for products and control this via either the category and apply to child products or via individual products.

I want for example to change to a 2 column view however want blocks to automatically move about based on this decision rather than the extra need of placing layout xml within the layout update xml field. I am wondering how would be best to approach this.

Basically this is what I want to happen in layout xml but do not think there are any conditionals for layout type set on products within xml:

<move element="catalog.product.related" destination="sidebar.additional" before="-"/>

On top of this i would also like a lot more control for example if there are no related products then move crosssell products there instead.

I am thinking that I may need to remove these blocks from layouts and then add conditionals within the sidebar.phtml to decide weather the block needs to be shown and then populate with code like below:

<?php echo $this->getLayout()
      ->createBlock('Magento\Catalog\Pricing\Render',
              "product.price.final",
                [
                    'data' => [
                        'price_render' => 'product.price.render.default',
                        'price_type_code' => 'final_price',
                        'zone' => 'item_view'
                    ]
               ]
              )
      ->toHtml();?>


Related Questions


CE 1.9 - CSS class for CMS Page Layout update

Updated June 29, 2015 18:04 PM



Magento 2 - Updating Product list page Layout

Updated April 06, 2018 11:09 AM

Duplicate product/view tabs element in Magento 2

Updated March 13, 2017 15:09 PM