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?

TFS
  • 4,319
  • 17
  • 46
  • 74

2 Answers2

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?.

Khoa TruongDinh
  • 32,054
  • 11
  • 88
  • 155
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.

Krishna ijjada
  • 8,927
  • 6
  • 41
  • 70