Jump to content

Override theme template from module - PS1.7


Recommended Posts

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...