0

I have a CMS page, and in certain place it references a custom block from my module as such:

{{block class="My\Notification\Block\NotificationForm" name="notification.form" template="My_Notification::form.phtml"}}

This works and shows the template, but I don't know how to define child block within this template. In my module I have view/frontend/layout/default.xml:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="notification.form">
            <block name="notification.form.inner" class="Magento\Framework\View\Element\Template" template="My_Notification::inner.phtml" />
        </referenceBlock>
    </body>
</page>

and in my form.phtml I have

...
<?php echo $this->getChildHtml('notification.form.inner') ?>
...

but it just doesn't show up. I tried various other things, including trying to use addChild() in my block class constructor, but no matter what I try it just doesn't show up. What am I doing wrong?

1 Answer 1

0

For anyone interested, turns out the block can just be defined directly in form.phtml template using the following code:

<?php 
$block = $this->getLayout()->createBlock('Magento\Framework\View\Element\Template')->setTemplate('My_Notification::inner.phtml');
echo $block->toHtml();
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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