簡體   English   中英

在Handlbars中包括其他模板文件

[英]Including other template files in Handlbars

我有一個index.html文件,我正在使用它作為基本文件。 然后,我想將網站的各個部分分成較小的文件,以包含在我的基本文件中。 我正在嘗試通過導航菜單執行此操作。 我正在使用browserify包含模板文件。

index.html

<body>
    <div id="nav-template"></div>
</body>

導航把手

<script id="nav-template" type="text/x-handlebars-template">
    <p>This Is A Nav</p>
</script>

然后,我運行把手nav.handlebars -f templates.js

app.js

var $ = require('jquery');
var Handlebars = require('handlebars');
var templates = require('./templates');

var template = Handlebars.templates['nav-template']
var html = template();

$('#nav-template').html(html);

我的瀏覽器什么也沒有,也沒有錯誤。

nav.handlebars應該是:

<p>This Is A Nav</p>

使用外部處理程序欄文件時無需script標記

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM