更新时间:2023-02-11 19:20:58
听起来像是在寻找局部声音.部分是要包含在其他几个模板中的模板片段.您将在模板中执行以下操作:
Sounds like you're looking for a partial. A partial is a template fragment that you want to include in several other templates. You'd do something like this in your templates:
<script id="error" type="text/x-handlebars">
<!-- Error display stuff goes here -->
</script>
<script id="t" type="text/x-handlebars">
{{> error}}
</script>
然后注册部分:
Handlebars.registerPartial('error', $('#error').html());
完成后,您可以照常使用#t
:
Once that's done, you can use #t
as normal:
var t = Handlebars.compile($('#t').html());
var h = t({ ... });