Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
1 answer
67 views

Best method to use helper in any template

It seems to be impossible to use a helper in the template Magento_Catalog\templates\product\list\items.phtml. I have tried it via argument injection: app\design\frontend\company\base\Magento_Catalog\...
Black's user avatar
  • 3,431
0 votes
1 answer
703 views

`$this->getViewFileUrl` adding en_us to a url

I'm trying to add an image from my theme in template like <img src="<?php echo $this->getViewFileUrl('Vendor_Theme::images/image.svg'); ?>" /> But this url adds en_us. How can I ...
Robot__4's user avatar
  • 119
2 votes
1 answer
770 views

Adding custom logic to phtml

Very often it is needed to add some custom logic to templates. For example it can be checking if customer is logged or some information about product - if it's already bought by current customer or if ...
Bartosz Kubicki's user avatar
10 votes
3 answers
5k views

Magento 2: proper use of helpers

I'm starting to see more and more people declaring helpers classes in order to be able to use the following in the template files: $this->helper('Path/To/Helper/Class')->customMethod(); This ...
Raphael at Digital Pianism's user avatar
5 votes
3 answers
700 views

Where should i put my function if i need it only in one Template?

I got a template called dashboard.phtml and i want to add a function there. I thought it was a bad practice to write it directly in the template it self so where should i put it? The class for this ...
MCSell's user avatar
  • 183
7 votes
3 answers
8k views

Correct way of getting helper in template of custom block

What is the correct way of getting a helper in a template file of a custom block? In Magento_Search module there is a block: <referenceContainer name="header-wrapper"> <block class="...
zitix's user avatar
  • 2,192
7 votes
1 answer
9k views

Difference between $this->helper and Mage::helper

Is the following codes in the phtml $this->helper('catalog/category') and Mage::helper('catalog/category') returns the same object? What is the meaning of using $this->helper() and Mage::...
Manikandan Arunachalam's user avatar
1 vote
1 answer
805 views

What's your take on using a custom helper in templates? [closed]

I'm faced with a problem where I can either make a helper in my extension to do some simple task or override multiple block class functions. This is a utility function, so I would typically make a ...
laketuna's user avatar
  • 6,850
1 vote
1 answer
219 views

Why Is This Custom Module Helper Returning the Same Value In A Loop In A Template?

I have a custom module, called JLS_Composers, which is used to input a "composer." Each product can have one or more Composers associated with it (which is accomplished in the Product edit page). I ...
KevinD's user avatar
  • 13
0 votes
1 answer
3k views

Access input field values from form template in helper/controller classes

In a Magento checkout template there is a html tag for payment form: <ul class="form-list" id="payment_form_testmethod" style="display:none;"> <li> <input class="checkbox" ...
Qwerty's user avatar
  • 101
1 vote
2 answers
5k views

Call helper method from cms template

Is it possible to call a helper method to output a variable in a cms template? Similar in fashion to the way helpers can be called in layout files such as: <node helper="myhelper/myhelpermethod" /...
Marty Wallace's user avatar
3 votes
1 answer
4k views

Use template/block in a helper

I have a helper with this method to get the items in a customer's cart public function getCartData() { //Get cart DATA $quote = Mage::getSingleton('checkout/session')->getQuote(); $...
Steve Robbins's user avatar