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 helper, but it is going to be used in templates to manipulate outputs to the screen. For simplicity's sake, let's say I just want to replace the string ABC with XYZ in some cases, and it cannot be done via translation.

Here's the dilemma, since template files are not contained in the app directory, you could potentially get fatal errors when you disable the relevant extension and leave rogue helper calls in the templates. There are multiple template files where I would need to utilize this function. I've seen rogue helper calls break pages on multiple sites.

While I can also customize each of the templates to minimize potential errors, a simple Mage::helper('myextension')->convertString($str) would reduce the amount of work significantly.

What's your take on this kind of issue? I know it's subjective, but I did not find any useful reference online, and I just have my own judgement call. It doesn't hurt to hear what others have to say!

Not completely relevant but still here's one discussion.

  • I am not sure why a helper would be less work that the template changes since for both you should "ideally" have the template in your own theme and not edit the core template. you could also look into an event something like after_html and do your replace then but that will be resource heavy I guess unless you know exactly which blocks to check, – David Manners Oct 26 '14 at 22:12
  • @DavidManners, sorry maybe I wasn't too clear. I'm already using my own template files in the custom theme. I'm more concerned about multiple block rewrites vs. single helper function. The latter is a simpler solution, but it comes with a downside I described. Marius suggests a solution. – musicliftsme Oct 27 '14 at 15:10

First of all, it's better to have custom helpers than to override core classes.
If you use your helper in templates and you don't want to get errors if you disable your module, you should handle your helper calls like this.
Let's say your extension is called MyNamespace_MyExtension and you call your helper like this:


You should wrap your helper call in an if statement that checks if the module is exists and is enabled.

if (Mage::helper('core')->isModuleEnabled('MyNamespace_MyExtension')) {

This call makes use of the core helper. You would ask then, "how to check if the core module is enabled?". You don't need to check that. If Mage_Core is not enabled then nothing works.

| improve this answer | |
  • thanks for the answer. Do you ever/often (1) use customer helpers in the customer template files and (2) do you bother checking IsModuleEnabled if/when you do? – musicliftsme Oct 27 '14 at 15:13
  • I actually used this approach a lot of times. Mostly on product list pages and product view pages. And yes, I always check if the module is enabled. Actually sometimes I use isModuleOutputEnabled. It depends if my helper changes some of the existing values or adds new ones. If it adds new ones I use isModuleOutputEnabled. – Marius Oct 27 '14 at 15:16

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