How to Use Helper in Magento 2.0 Template

Dec 9, 20152474
How to Use Helper in Magento 2.0 Template

We are used to see Helper as an element that is global and always available. It’s created as a Singleton.

Everybody used the following construction: Mage::helper(‘[Modul] / [Helper Name]’)

Where do you need it?

You need it in templates. In our modules, when creating classes, we can define any unnecessary subjects in construct. But it doesn’t seem right to redefine other’s classes when coding, does it?

So how can you do it in Magento 2.0?

In Magento 2.0 templates there is a main object: $block.

Its class is a block that corresponds to the template.

Here you can also find our old famous variable $this.

Its class is Magento\Framework\View\TemplateEngine\Php

And here comes our “our precious”!

Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Andrey

Looking for an expert Magento 2 development team? Turn to BelVG!

magento development services

Magento Development Services

Take your online store to the next level with BelVG Magento development services

Get to know us

Partner With Us Looking for a partner to grow your business? We are the right company to bring your webstore to success. Talk to Andrey

4 Comments

  1. Hi i want to add subject in template email How to add subject in magento 2
    magento 1:-setTemplateSubject function
    magento 2:- ?

  2. Hi Mishel, creating helper in magento was so easy as i learnt it from here magenticians.com/create-helper-magento and your article has made it look more easier in magento 2.

Post a new comment

top
BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *