0

I have a custom Block, and I want to run some code before this block will be rendered. How to achieve this?

I don't want to place my code inside Block method and run it from the template.

I don't want to place my code inside __construct, because it's no good for performance.

I think there is a maybe some event in Magento, that I can use for this.

I will be glad to any thoughts. Thanks.

1 Answer 1

2

You can use _beforeToHtml method of Magento\Framework\View\Element\AbstractBlock in your block class, it call before rendering html of your block file.

0

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.