I have encountered a problem when trying to create a block in a controller to the extent that I need the block created in the controller to also create an object of type ViewModel.
What I am trying to achieve, but I want to do it through the code in the controller instead of using the design file: –
My code in the controller is as follows: –
_view->getLayout(); /** @var BubAdvancedReviewBlockExpertReviewExpertReviews $block */ $block = $layout->createBlock(BubAdvancedReviewBlockExpertReviewExpertReviews::class,null,('advanced-review-helper' => 'BubAdvancedReviewHelperBlockHelper')); $block->setTemplate('Bub_AdvancedReview::expert_reviews.phtml'); $layout->createBlock()->setData(); return $this->getResponse()->setBody($block->toHtml()); } }
Does anyone know if this can be done?
Thanks in advance