Extending Handlebars.js templates

心不动则不痛 提交于 2019-12-07 07:43:12

问题


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.


回答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.




回答2:


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.



来源:https://stackoverflow.com/questions/22474194/extending-handlebars-js-templates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!