4

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.

flaudre
  • 2,358
  • 1
  • 27
  • 45
A23
  • 1,596
  • 2
  • 15
  • 31

2 Answers2

1

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.

melc
  • 11,523
  • 3
  • 36
  • 41
  • What is the difference between a partial and a component? – A23 Mar 18 '14 at 10:02
  • @A23 a component is like a `view` but somewhat more generic in fashion, as custom element tags can be specified, see here http://stackoverflow.com/questions/18593424/views-vs-components-in-ember-js also check out this for difference between partial and view http://stackoverflow.com/questions/19982257/ember-js-handlebars-render-vs-outlet-vs-partial-vs-view-vs-control – melc Mar 18 '14 at 10:22
  • @A23 also to simplify things a bit i think of `partial` as something stateless without any backing classes that is simply concerned with rendering a template in place. – melc Mar 18 '14 at 10:27
  • This seems like what I'm looking for. Thanks @melc! – A23 Mar 19 '14 at 05:33
1

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.

splattne
  • 102,760
  • 52
  • 202
  • 249