简体   繁体   中英

Extending Handlebars.js templates

Is there a way to extend templates like in Django? My base template has a header that only needs to be a few pages. I'd like to change that for the the other templates.

Something similar to

{% extends "base.html" %}
    ...
{% endblock %}

I'm using Ember.js.

As far as i know this notation does not exist, also i haven't seen the concept of inheritance on handlebars templates layer.

However, i can think of two ways to achieve what you want,

1. using the {{partial}} helper http://emberjs.com/guides/templates/rendering-with-helpers/

The {{partial}} helper can render the header part and it can be included only on those templates of the pages that require the header.

2. using layouts http://emberjs.com/guides/views/adding-layouts-to-views/

Have two layouts one with the header and another without it, then specify on the pages/views that need the header the corresponding layout using the layoutName property.

I was looking for the same as I come from the same Django background. Here I've found exactly what you are looking for. It uses another module from npm called Handlebar-layouts. which is really useful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM