【发布时间】:2022-01-06 22:46:27
【问题描述】:
所以我想直接从块文件中调用模板 phtml 文件,而不是将它们附加到布局 XML 文件中。
提前谢谢你!
【问题讨论】:
所以我想直接从块文件中调用模板 phtml 文件,而不是将它们附加到布局 XML 文件中。
提前谢谢你!
【问题讨论】:
如果你想在没有 xml 的情况下调用它,为什么不直接从 phtml via
<?php echo $this->getLayout()
->createBlock('Magento\Framework\View\Element\Template')
->setTemplate('Vendor_Module::template.phtml')
->toHtml(); ?>
你可能在你的块中使用相同的方式,但我没有测试过。
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$content = $objectManager->create('Magento\Framework\View\Element\Template');
$content->setTemplate('Vendor_Module::template.phtml');
$content->toHtml();
【讨论】: