How do I pass data from the controller to my block file? Below is the code which I am using inside the controller.


1 Answer 1


You can do it like this:

using the block generator arguments (check vendor/magento/framework/View/Layout/Generator/Block.php and see what it does inside the createBlock() and inside it in $block->addData() method):

$block = $this->_view->getLayout()
        ['data' => $data]

you can see an example of this kind of usage in vendor/magento/module-banner/Controller/Adminhtml/Banner/Widget/Chooser.php.

OR you can define a custom setter in your block class and pass the data like this:

  • Thanks Diana Botean...once again.... Commented Feb 19, 2021 at 8:38
  • and once again, you are most welcome :) cheers!
    – Diana
    Commented Feb 19, 2021 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.