I have a block within a phtml file: the block is not associated with a controller.

echo $this->getLayout()

my question now is how do i call the methods of the block.

i.e within the class

Top-> CmsAndTemplatePages->Block->Cmspages is a method called


how do i access this method from the phtml page


1 Answer 1


If you want to call the method of Top\CmsAndTemplatePages\Block\Cmspages then try to below code:

  //Initiated   block class 
    $Cmspages = $block->getLayout()

 //Call method of this class 

Here myTESTMethod is a method of this class.

And if you want to print the html output of this block then use

<?= $Cmspages->toHtml() ?>
  • This works but you can only call public methods. I have a feeling _toHtml is a protected one.
    – Marius
    Jan 15, 2019 at 14:17
  • OPPS, you can only class pUblic function not Protected and other
    – Amit Bera
    Jan 15, 2019 at 14:21

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.