Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Template Inheritance for Handlebars

I am trying for template inheritance from base.html to other templates using handlebars.But am not getting soul for this.

Please, Can anyone help me out with simple DEMO. with base.html , extend.html

For example , Base.html

<html><head></head>
<body>
{% block content %}{% endblock %}
</body>
</html>

Extend.html

{% extends "base.html" %}
{% block content %}<h1>Foobar!</h1>{% endblock %}

Which files I need to include in base.html ......?

like image 904
Mulla Pervez Avatar asked Nov 05 '12 06:11

Mulla Pervez


People also ask

What is Template inheritance?

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.

Is handlebars a template engine?

Handlebars: What it is and Why to Use itHandlebars is a logic-less templating engine that dynamically generates your HTML page.

Is handlebars a template language?

Handlebars is a simple templating language. It uses a template and an input object to generate HTML or other text formats. Handlebars templates look like regular text with embedded Handlebars expressions.


1 Answers

Handlebars does not provide template inheritance out-of-the-box.

However, there are libraries that provide the helpers necessary to do template inheritance. My favorite is Wax On because it is based on the template inheritance in Pug and Django and works as you expect.

There is also handlebars-layouts which works a little differently, but it can also run client-side, if needed.

like image 56
Keith Shaw Avatar answered Sep 20 '22 11:09

Keith Shaw