Overriding Module Template Files

One new feature of Pligg 2 is the ability to override a module’s template files with a copy stored in your template’s directory. The great thing about this feature is that it allows you to upgrade a module without losing design changes, since the template files are being stored in a different directory.

I am going to use the “Sidebar Stats” module as an example to demonstrate how to do this. To start, we need to find the name of the file that the Sidebar Stats module inserts into your design. In this case the file happens to be found at:

/modules/sidebar_stats/templates/sidebar_stats.tpl

Let’s copy that file and paste it into our template directory like so:

/templates/bootstrap/modules/sidebar_stats/sidebar_stats.tpl

Now, let’s open up the new file and test if the template is overriding the module’s own template file. I’m going to paste in the following:

<h1>Hello World</h1>

Next, refresh the homepage and look at the sidebar to see if it had any effect.

hello_world_sidebar

Yay! Your first template override!

I’d like to now mention that there are a few gotchas about template overrides. You should pay attention to module updates, in case there are important changes made to the module’s template files that you will need to copy over to your override file. Another important thing of note is that not all modules are going to work when applying this concept. This is still a pretty new feature, and it could use some improvement. If you want to try to help us make this feature work even better, you can find us on Github.

Add Comment Register



Leave a Reply