In the Django framework, web page templates can inherit from other templates. In your child template, you define blocks of code which override like-named blocks in parent templates. I'm guessing there are other back-end templating systems which also work this way, but Django is the one I'm familiar with.
Do any of the existing javascript template systems support django-style inheritance?
It is possible to inherit from a template class. All the usual rules for inheritance and polymorphism apply. If we want the new, derived class to be generic it should also be a template class; and pass its template parameter along to the base class.
Template inheritance allows you to build a base “skeleton” template that contains all the common elements of your site and defines blocks that child templates can override. Sounds complicated but is very basic. It's easiest to understand it by starting with an example.
In JavaScript, an object can inherit properties of another object. The object from where the properties are inherited is called the prototype. In short, objects can inherit properties from other objects — the prototypes.
Pug's template inheritance is a powerful feature that allows you to split complex page template structures into smaller, simpler files. However, if you chain many, many templates together, you can make things a lot more complicated for yourself.
What you're looking for if you want template inheritance and DTL syntax, is Nunjucks :
http://mozilla.github.io/nunjucks/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With