Templating just got easier

Posted by Development Team in Development, Styles with the tags , , , , on July 31st, 2008

One of the advantages of a face-to-face meeting is that feature requests and feature discussion can be much more effective; at least if it is about minor window dressing as opposed to huge changes. To curb the wave of requests right here: you should have been there, the opportunity has passed ;-). People watching the SVN repository may know already: there were some major changes in the past two weeks. A lot is moving right now in the active branches, but that’s for future posts.

Today it is a great pleasure for us to unveil a new feature for the 3.0 branch, to be released with 3.0.3: Template Inheritance.

It is a direct result of our meeting with Andy Miller and is intended to give more freedom to style and template authors. To cut to the chase and explain what it actually does: If you base a new template set on an existing one, but if you only want to change a few things, you still needed to copy all template files. Having unaltered copies certainly works fine, but if there is an update for the original, it can be very tedious to merge the changes to all derived templates.

So – the answer to that is adding template inheritance. Now a simple declaration “inherit_from” in the template configuration file will tell the template engine to fall back to files of a different template set, if there is anything missing in the current one. The nice thing about this is that the process is completely transparent after template compilation and comes at practically no extra costs during runtime.

To give you an idea: Let’s say you want a new template set named inherits, which uses prosilver as base (especially note the very last line):

Code: Select all
# General Information about this template

name = inherits
copyright = © phpBB Group, 2007
version = 3.0.2

# Defining a different template bitfield
template_bitfield = lNg=

# Are we inheriting?
inherit_from = prosilver

And let’s just add just one template file to that new set:

Code: Select all
$ ls -l
-rw-r--r-- 1 kell dev 8986 Jul 30 15:22 editor.js
-rwxr-xr-x 1 kell dev 215 Jul 28 16:52 faq_body.html
-rw-r--r-- 1 kell dev 4375 Jul 30 15:22 forum_fn.js
-rw-r--r-- 1 kell dev 2517 Jul 30 15:22 styleswitcher.js
-rwxr-xr-x 1 kell dev 764 Jul 28 16:52 template.cfg

The sole html file is pretty trivial – I’m sure you folks will come up with far cooler applications. It does use includes however:

Code: Select all
<!-- INCLUDE overall_header.html -->
<h2>This is overridden</h2>
<!-- INCLUDE jumpbox.html -->
<!-- INCLUDE overall_footer.html -->

Okay. Let’s see how that works out. We see our new template in the list:

The partial template set appears in the list normally.

The partial template set appears in the list normally.

… and can install it:

The install shows the dependency.

The install shows the dependency.

We can now use it in a style just as any other template:

And - drumroll - we can use is.

And – drumroll – we can use it.

And take it for a ride – all the included template files are taken from prosilver:

The page uses all elements from prosilver.

The page uses all elements from prosilver.

Back in the ACP, we can view the cache details to see where the template engine took the source from:

The ACP gives information about the origin of a given template file.

The ACP gives information about the origin of a given template file.

So far so good, we can’t wait to see what people will do with it. Have fun.

In the implementation for 3.0 there are a few limitations to this, which we won’t keep secret. For starters, there is no stacking of fallbacks. It’s only possible to fallback to a template that does not itself declare to be dependent on another template. The other major limitation is that it only affects the files managed by the template engine (*.html) and not the static javascript files bundled with many templates. Those static files still have to be copied, or manually linked using the new {T_SUPER_TEMPLATE_PATH} template variable.

Note: Although we introduce this new feature in the 3.0.x line the branch is still feature frozen. We will however include very important features if we wish to do so and if they fit nicely into the existing code. New features are discussed by the development team and need to be approved by all members.

8 Responses to “Templating just got easier”

Posted by Derky on July 31st, 2008 at 11:26 pm:

So now you have 3 options for your custom style:
– your own template(set)
– a template from an other style:

Code: Select all
required_template = prosilver

– the new feature inherit!

It is really good to see that the template engine is being improved to make things easier. Nice work!

Posted by michaelo on August 3rd, 2008 at 12:51 am:

A few months back I made a similar suggestion to the dev team… The proposal was based on my One Copy Mod, which is 100% functional…

I suggested the addition of two common files folders, one for prosilver and the other for subsilver…
A small edit to the template engine allow for automatic loading the correct template page from the appropriate common folder…
This method also provides for partial inheritance which the proposed system does not appear to facilitate…

In effect, each new template need only include those file where the style designers differs from the the default style, thus assuring no restrictions to the creative process…
Further, this proposal also provided for the inclusion of mod templates in the common folder directory further reducing file count and reducing mods edit times…
The mod does not interfere with the normal template functionality and does not require additional queries or ACP entries…

It’s a shame I never received any reply to my pm, as the mod does exactly what it says on the tin, and of course I would have save a lot of time and energy getting it working…

Assuming any style template can to be inherited from any other… partial inheritance could also be added by simply checking for the existence of the template file in the original folder and if not found, in the
‘inherited from style folder’… thereby allowing partially inheritance…

Posted by nikhil on August 8th, 2008 at 9:24 am:

This is gonna be great improvement concerning minor templates changes that people like me would like to implement in my website.
It will be very useful, when you like one template but not a “certain/specific” feature.

Posted by Double_J on August 9th, 2008 at 6:18 pm:

This indeed is a great improvement, seeing that a huge number of templates/styles only feature a few minor changes, which usually ment that an entire templateset needed to be copied.

I however have one question though regarding the limitations, you say that you cannot inherit from a template which already is inherited. My question is, do you check this, or do you as a style author have to check wether or not your superstyle(or parent or whatever) is inherited or not?

Posted by Kellanved on August 10th, 2008 at 8:37 pm:

Yes, the ACP checks it and will refuse to install such templates.

Posted by T50 on August 15th, 2008 at 2:13 am:

So this would mean that if i edit prosilver’s template, let’s say the overall_header to add a link on it, that change would show up in other styles as well.. correct?

also what about subsilver2? would that be included in this new feature?

Posted by Kellanved on August 15th, 2008 at 11:20 am:

I would suggest keeping the questions/discussion on the forum. If your template is based on another one, it will use files of the superstyle. Prosilver is not hardcoded in.

Posted by Jesse on May 8th, 2009 at 2:25 pm:

There is obviously a lot to know about this. I think you made some good points in Features also.

Commenting is disabled for this blog post