0

Can someone provide working example how to it?

I've heard that also it is good way to replace completely block class in layout for custom one extending from replaced one and then just add to custom block's constructor. Example of its would be also nice.

1 Answer 1

0

You mean to create a block with a constructor argument?

In Magento, blocks usually don't have constructor arguments. Instead, you can use a setter that you cann from the layout xml to add or change the data / behaviour you want.

If you later develop another module that affects your block, the setter can be called again to change the value to something new. The block does not need to be re-created at that time.

3
  • I mean to add new dependency to block with custom logic and than call that new class' method in template Feb 13, 2017 at 8:55
  • So you want to use the same template, but attach a different class to it? The new class extends the old one? Have I understood you correctly?
    – Wouter
    Feb 13, 2017 at 13:14
  • No - I want to add to ids contructor new class for example some helper or model - and how to do it via layout and then call that class' methods in template Feb 14, 2017 at 7:23

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.