We can put our logic inside the block. Why we still need a helper? What is the best practice of using a helper class?
Asked
Active
Viewed 656 times
2 Answers
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
-
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 05 '16 at 07:02