Question

On the PDP I am trying to create a new block (product.info.main.inner) inside of product.info.main so I can pass arguments to it and then move all off the child blocks inside product.info.main.inner. I'm trying to use the following but the section is blank on the frontend, does anyone know what is going wrong please?

   <referenceContainer name="product.info.main">
       <block class="Magento\Framework\View\Element\Template" name="product.info.main.inner">
         <argruments>
           <argument name="add_attribute" xsi:type="string">itemscope itemtype="http://schema.org/Product"</argument>
         </arguments>

           <block name="product.brand.logo" class="Magento\Catalog\Block\Product\View" template="Magento_Catalog::product/brand-logo.phtml" after="-" />

        </block>
   </referenceContainer> 

   <move element="page.main.title" destination="product.info.main.inner" before="-" />
Was it helpful?

Solution

There is nothing going wrong per se as this is expected behaviour.

To render a block (child) within a block (parent), you need to call the child block from within the parent block. You can do this with <?= $block->getChildHtml('block.alias.here') ?> or alternatively load all child blocks by not passing an argument <?= $block->getChildHtml() ?>.

So what you need to do here is to add a template to your block and within it add <?= $block->getChildHtml('product.brand.logo') ?>.

This also helps explain a big difference between a container and a block. Containers will automatically render child blocks whereas blocks will not.

Also related, getChildHtml will render the block based on the alias (as attribute), if no alias is set like in your example then it will default to the same value as name. It's important to know this else you may get confused at some point in the future.

OTHER TIPS

Try with adding blank template file to this block product.info.main.inner.

            <block class="Magento\Catalog\Block\Product\View" name="bundle.product.view.options.notice" template="Magento_Bundle::catalog/product/view/options/notice.phtml"/>
            <block class="Magento\Bundle\Block\Catalog\Product\View\Type\Bundle" name="product.info.bundle.options" as="type_bundle_options" template="Magento_Bundle::catalog/product/view/type/bundle/options.phtml" before="-">
                <container name="product.info.bundle.options.top" as="product_info_bundle_options_top">
                    <block class="Magento\Catalog\Block\Product\View" name="bundle.back.button" as="backButton" before="-" template="Magento_Bundle::catalog/product/view/backbutton.phtml"/>
                </container>
                <block class="Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option\Select" name="product.info.bundle.options.select" as="select">
                    <arguments>
                        <argument name="tier_price_renderer" xsi:type="object">\Magento\Bundle\Block\DataProviders\OptionPriceRenderer</argument>
                    </arguments>
                </block>
                <block class="Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option\Multi" name="product.info.bundle.options.multi" as="multi"/>
                <block class="Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option\Radio" name="product.info.bundle.options.radio" as="radio">
                    <arguments>
                        <argument name="tier_price_renderer" xsi:type="object">\Magento\Bundle\Block\DataProviders\OptionPriceRenderer</argument>
                    </arguments>
                </block>
                <block class="Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option\Checkbox" name="product.info.bundle.options.checkbox" as="checkbox">
                    <arguments>
                        <argument name="tier_price_renderer" xsi:type="object">\Magento\Bundle\Block\DataProviders\OptionPriceRenderer</argument>
                    </arguments>
                </block>
            </block>
        </referenceBlock>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top