No. Magento uses one central layout tree, not multiple depending where they are defined. However, if you look in \Magento\Framework\View\Layout\Generator\Block::createBlock()
, you'll notice that the block is created (and the constructors are called) before the name is set:
public function createBlock($block, $name, array $arguments = [])
{
$block = $this->getBlockInstance($block, $arguments);
$block->setType(get_class($block));
$block->setNameInLayout($name);
$block->addData(isset($arguments['data']) ? $arguments['data'] : []);
return $block;
}
The getBlockInstance()
method creates the block and calls the constructors. Then, the name is set.
Next, the block is set in layout, in the \Magento\Framework\View\Layout\Generator\Block::process()
method. Later on in that method, the setLayout()
method is called on each block, which provides the block with an instance of Magento\Framework\View\Layout
and calls the _prepareLayout()
method on each block. The right place to set children is inside your block's _prepareLayout()
method, since this will be called after the name is set, the block is set in layout, and the block has a reference to the layout object.
I'd do it like this:
protected function _prepareLayout()
{
$childBlock = $this->getLayout()->createBlock('Your\Class');
$this->addChild($childBlock);
}
Please let me know if you have any questions!
Best Answer
To change the layout of individual product detail page, as you have created the child theme assuming your child theme path is something like this
magento_root/app/design/frontend/company_name/theme_name/
Now navigate to your child theme and follow these steps.
Hope this helps your question.