[英]Passing arguments to a Blaze template
假设我有一个通用的标记,它将在我的网站中重复出现,只有一些小的差异。
例如,我有一堆<div>
元素,它们都有一个标题。
带有 class: section-title
元素的样式都相同,但它们的文本内容不同。
我想制作一个模板来表示标题,就像这样:
<template name="section-title">
<div class="section-title">
<span> Profile </span>
</div>
</div>
除了,我需要“个人资料”可以互换,因为我有很多不同的部分:“个人资料”、“联系信息”等。
在 Blaze 中执行此操作的最佳方法是什么?
您可以使用模板参数或将模板当前数据上下文设置为适当的参数列表。
HTML
<template name="sectionTitle">
<section class="section-title">
<span>{{title}}</span>
</section>
</template>
{{> sectionTitle title="Profile"}}
<template name="parent">
{{> sectionTitle args}}
</template>
JS
Template.parent.helpers({
args: function(){
return {
title: "Profile"
};
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.