简体   繁体   中英

Including other template files in Handlbars

I have a index.html file that i am using as my base file. I then want to separate sections of the site into smaller files to include in my base file. I am trying to do this with the navigation menu. I am using browserify to include the template files.

index.html

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

nav.handlebars

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

I then run handlebars 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);

I get nothing in my browser and no error.

nav.handlebars should be :

<p>This Is A Nav</p>

No need for the script markup when using external handlerbar files

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