Jurist Posted June 29, 2023 Share Posted June 29, 2023 Hello, I am trying to create a module, which needs to alter the active theme .tpl block, for eg: {block name='product_brand_below'} from product.tpl file. How do I do that? Using module front controller? I found $this->setTemplate('module:sample_module/views/templates/front/product.tpl'); method, but not exactly sure when it needs to be fired. {extends file=$layout} {block name='product_brand_below'} <p>Best brand ever</p> {/block} Is that the approach I should try to go with? I know I can just override the template file with child-theme but that's not something I am looking for. Thanks for any replies Link to comment Share on other sites More sharing options...
ps8modules Posted June 29, 2023 Share Posted June 29, 2023 There is no officially way to override the core template files of the theme from module. The best way is to create a child theme, and override only the files you need. The only thing you can do is to create a backup of the tpl file when installing your module and upload your tpl file to the original location. Just use the php functions file_get_contents, str_replace and file_put_contents. You also need to think about reverting the changes when you uninstall the module. Link to comment Share on other sites More sharing options...
Jurist Posted July 4, 2023 Author Share Posted July 4, 2023 Thanks but creating a child template for a small code insertion, while child template can already exist under a different name is not really an acceptable solution. Link to comment Share on other sites More sharing options...
ps8modules Posted July 4, 2023 Share Posted July 4, 2023 Hi. There are no other options. Just disable the module and program your own. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now