0

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="-" />
1

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.

1
  • 1
    Ah that's fantastic, thanks a lot for the explanation makes perfect sense! :D – NoDachi Mar 11 at 21:02
0

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

0
            <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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.