我有一个部分包含我的网页的通用结构:
<script id="page-template" type="text/x-handlebars-template">
.....
<div class="page-content">
<div class="page-header">
<h1>{{title}}
<small>
<i class="ace-icon fa fa-angle-double-right"></i> {{subtitle}}
</small>
{{/if}}
</h1>
</div>
......
</div>
</script>
然后,我从每个页面调用部分传递属性 title 和 subtitle。它适用于常量属性,例如:
{{#> page title="Customers" subtitle="List of customers"}}
<!-- Page HTML -->
{{/page}}
但是,当我尝试传递变量时它不起作用:
{{#> page title="Customer" subtitle="{{customer.name"}}
<!-- Page HTML -->
{{/page}}
它显示 {{customer.name}} 而不是客户的真实姓名。有可能使这项工作吗?
提前致谢!
最佳答案
我终于设法完成了这项工作。我在这里做出回应,以防其他人受益:
{{#> page title="Customer" subtitle=customer.name
<!-- Page HTML -->
{{/page}}
只需要删除{{}}和""。请注意,customer 是模板中可用变量的名称。
关于javascript - Handlebars : Pass dynamic variables to partials,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36335747/