1

How to add bare HTML to a block e.g:

$block = $result->getLayout()->getBlock('category.description');
$block->setTemplate('Vendor_Module::myTemplate/blank.phtml')
->toHtml('<p>My Content</p>');

Is there a way to dynamically add content to a block perhaps without use of templates or any other way appreciate?

3

You should try this

 echo $this->getLayout()->createBlock("Vendor\Module\Block\Myblock")- 
>setTemplate("My_Module::history-suite.phtml")->toHtml();
  • I know that Not what I was looking for! however I've found a solution thanks. – Juliano Vargas Aug 1 at 11:15
  • please Upvote. If you appreciate. – KHIMAJI VALUKIYA Aug 1 at 11:18
  • Helpful for others not for me – Juliano Vargas Aug 1 at 11:19
2

I've found a solution pretty simple.

$block = $result->getLayout()->setData(['test'=> 'Content here'])->getBlock('category.description');
$block->setTemplate('Vendor_Module::myTemplate/blank.phtml')
->toHtml();

Then my blank.phtml:

<?php print_r($this->getData()) ?>

It prints: Array ( [test] => Content here [module_name] => Magento_Catalog )

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.