简体   繁体   English

扩展Handlebars.js模板

[英]Extending Handlebars.js templates

Is there a way to extend templates like in Django? 有没有办法扩展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. 我正在使用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/ 1.使用{{partial}}帮助器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. {{partial}}帮助程序可以呈现标题部分,它只能包含在需要标题的页面的那些模板中。

2. using layouts http://emberjs.com/guides/views/adding-layouts-to-views/ 2.使用布局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. 有两个布局,一个带有标题,另一个没有它,然后使用layoutName属性在需要标题的页面/视图上指定相应的布局。

I was looking for the same as I come from the same Django background. 我一直在寻找同样的Django背景。 Here I've found exactly what you are looking for. 在这里,我找到了你正在寻找的东西。 It uses another module from npm called Handlebar-layouts. 它使用来自npm另一个名为Handlebar-layouts的模块 which is really useful. 这真的很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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