0

We can put our logic inside the block. Why we still need a helper? What is the best practice of using a helper class?

1

As far as I know, when calling a helper in your template, that is equal to the using object Manager directly. So, we should inject the helper in the constructor of the block. This is the best practice for using helper in Magento 2. We can read more What is helper in Magento?.

0

Why we still need a helper?

It is an object that will contain practical functions for you and you can call it from anywhere, you just load your helper to use it.

public function spmethifn()
{

}

Helpers concept remain same in Magento 2 compare to Magento 1.

You can find a very good answer from Marius♦ here

Hope it helps.

  • FTR, the linked answer starts with "Theoretically you should never use helpers.", so it's a good idea to read the whole thread. – Fabian Schmengler Sep 5 '16 at 7:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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