0

I can not render my custom block within my custom template,

Point is on newsletter subscriber, I extend newsletter_subscriber_form.xml,

Add container within my block but it says that template is invalid,

When is added in existing reference block nothing happened,

When I put a template in an existing block of this layout

(e.q. Magento\Backend\Block\Widget\Grid\Massaction)
It renders but I need my custom functionality.

Layout block

 <container name="content">
            <block class="Pool\Module\Block\Adminhtml\Subscriber\Button" name="button" template="Pool_Module:button.phtml" />
 </container>

path of template is on Pool/Module/view/adminhtml/templates/button.phtml

Block

<?php
namespace Pool\Module\Block\Adminhtml\Subscriber;

use Magento\Framework\View\Element\Template;

class Button extends Template
{
    public function __construct(Template\Context $context, array $data = [])
    {
        parent::__construct($context, $data);
    }

    public function addNewSubscriber()
    {
        var_dump('hi');
    }
}
0

please try to use below code.

<?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>
        <referenceContainer name="content">
            <block class="Pool\Module\Block\Adminhtml\Subscriber\Button" name="button" template="Pool_Module:button.phtml" />
        </referenceContainer>
    </body>
</page>
  • Exception #0 (Magento\Framework\Exception\ValidatorException): Invalid template file. NOTE: <container name="content"> is added by me, he is not existing in certain layout. – Newb Feb 7 at 12:08

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.