Using 2.1.3, I am loading admin tab content by calling a block directly in the Tabs.php
file:
protected function _beforeToHtml()
{
$blockClass = "MyNamespace\MyModule\Block\Adminhtml\Section\Edit\Tabs\BlockClassName";
$this->addTab(
'tab_title',
[
'label' => __('Tab Label'),
'title' => __('Tab Title'),
'content' => $this->getLayout()->createBlock($blockClass)->toHtml(),
'active' => true
]
);
}
Within the template phtml file I've set in the BlockClassName.php
file, I'd like to use $block->getChildHtml('child_block_name')
.
I've tried using the addChild
(per Adding a Child Block Programmatically) to the BlockClassName::_construct()
, but am getting an error:
vendor/magento/framework/Data/Structure.php(603): Magento\Framework\Data\Structure->_assertElementExists(NULL);
Where it looks like the vendor/magento/framework/View/Element/AbstractBlock::setChild()
is trying to pass in the block's layout name (line 380) - do I need to define the block in a layout in order to add a child block?