0

im trying to insert a custom block inside another block from the core. but for some reasons i cannot do it using referenceBlock. though its working if i use referenceContainer on the 'content', im trying to do it in checkout_cart_index.xml. heres my layout.xml.

<body>
    //this one is working
    <referenceContainer name="content">
        <block class="Magento\Framework\View\Element\Template"
               name="sample.name"
               before="-"
               template="My_Module::template.phtml" />
    </referenceContainer>

    //this one is not working. 
    //i also tried using renderer.list as reference block name. still not working
    <referenceBlock name="checkout.cart.item.renderers">
        <block class="Magento\Framework\View\Element\Template"
               name="another.sample.name"
              template="My_Module::template.phtml"/>
    </referenceBlock>

</body>

i have no idea whats wrong since the referenceContainer is working

0

That is one of the main differences between container and block.

Container will automatically render it's child blocks whereas block will not.

To render a child inside most blocks you must add <?= $block->getChildHtml('another.sample.name') ?> inside the parent blocks template. You need to pass in the alias defined on the block, if no alias is set then it will use the name attribute.

I say most blocks as some blocks will contain <?= $block->getChildHtml() ?> which will render all child blocks similar to a container.

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.