2

I'm trying to overwrite the catalog list template in a custom module. That template is already being overwritten by another module in one specific magento implementation. How can I write my module to play nicely with that module if it's installed, and still work the same if the other module is not installed?

I.e. if I copy the other module's template file and modify that, then my module won't work without the other module installed. And if I copy the base template and modify that, then the other module won't work.

How do I get around this?

1 Answer 1

1

Magento 1 answer

That depends ;)

I assume that module has additional methods that are called in the template and then cause an error if the given module is not installed?

if the module works with the data array of varien object, for getters for example you could call getData('custom_module_value') instead of getCustomModuleValue() in your template.

But if the modules template calls some 'real' method, I think you would have to implement a condition that asks if the module is installed.

You can do this in 2 ways I think:

  1. would be an easy if in the template (but seems not really nice since it adds complexity to your template): <?php if(Mage::helper('core')->isModuleEnabled('MyCompany_MyModule')): ?>

  2. would be, to create a helper, that wraps that function above, and then set the template based on the result of the helper method with something like this in the layout:

<block type="module/block" name="myblock">
  <action method="setTemplate">
       <template helper="mymodule/myhelper/getTemplatePath"/>
  </action>
</block>
3
  • Thank you! Your #2 option there is exactly what I was looking for. I'm going to take a stab at that as it seems to be the "right" way to do it.
    – nicthu
    Commented Feb 17, 2016 at 21:14
  • nice, pls tell me if it worked since im not 100% sure if the xml notation is exaclty right like i wrote it, but i know that you can do sth like that Commented Feb 17, 2016 at 21:21
  • Yep that worked, I had to do some futzing around to make my module layout updates load after the other one is all. Thanks again!
    – nicthu
    Commented Feb 17, 2016 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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