0

I've been turning the internet upside down trying to find out how to simply override a contrib module's theme() file. Although I have find many ways that should work, no result pops up and I can't really troubleshoot why.

To be more specific, I want to override the output of the file (/sites/all/modules/contrib/commerce/modules/cart/theme/commerce-cart-block.tpl.php) through theme('commerce_cart_block').

Now, I've tried many things. I have tried something called suggestions trying trying to make a file named block--commerce--commerce_cart_block.tpl.php in my theme directory plus several other varies of names. I've also tried setting new path through custom_checkout_theme_registry_alter's passed array. But now changes are visible, with or without clearing the cache each attempt.

I'm clearly missing something since this should in my eyes be both easy to do and needed to be editable.

So the question in short; How can I with as good practice as possible override the theme file of a contrib module and use it's passed variables?

0

2 Answers 2

1

Copy commerce-cart-block.tpl.php file to your theme and edit that copy. Remember to clear your cache before you reload the page. That's all. Don't rename. Don't play with suggestions.

6
  • This action doesn't change the output (for me). I've copied into my default theme's template directory with the same name. Any idea why that won't do the trick? Jun 17, 2013 at 15:09
  • @RobinCastlin Nope, if module is properly written, it should work. If it's written bad, and path to file is hardcoded, nothing will help.
    – Mołot
    Jun 17, 2013 at 18:05
  • In this case it's the commerce module, which should be written properly. Is there any way for be to troubleshoot this? At the moment it either works or doesn't. Kinda hard to base assumptions on that. Jun 18, 2013 at 8:01
  • JurgenR's answer is exactly this: a way to troubleshoot.
    – Mołot
    Jun 18, 2013 at 8:03
  • I tried that, but my project just gets stuck trying to enable simple_html_dom. So far I've tried adding up to 1024M allowed limit, but still no luck. Any suggestions? Jun 18, 2013 at 9:15
1

Use theme developer.
Theme Developer relies on the Devel module as a dependency. Once enabled, you may click on any part of the page and a sexy popup display shows which theme function/template outputted the HTML, and what other files could have done so. Armed with this info, a themer may quickly and accurately override the presentation. Further, all the variables passed into the template/function are presented for review.
With devel_themer you can see which template, process and preprocess are currently used for all different regions / blocks / fields etc and in your case, which candidate template files and functions can be used.
Only caution is to only activate the module when needed and disable it afterwards because it injects markers into the DOM, which can break the lay-out.

2
  • I tried that, but my project just gets stuck trying to enable simple_html_dom. So far I've tried adding up to 1024M allowed limit, but still no luck. Any suggestions? Jun 18, 2013 at 9:16
  • Seems like there's something far more wrong than just a template override! You can try changing theme to default, disabling custom and contrib modules to see what's causing this issue. Good luck!
    – JurgenR
    Jun 18, 2013 at 13:37

Your Answer

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

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