javascript - 将参数传递给 Blaze 模板

标签 javascript html templates meteor meteor-blaze

假设我有一个共同的标记,将在我的整个网站中重复出现,只有一些小的差异。

例如,我有一堆 <div>都有标题的元素。

类元素: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"
    };
  }
});

关于javascript - 将参数传递给 Blaze 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31223890/

相关文章:

javascript - VueJS Vee-Validate 验证未在输入时发生

javascript - 我想在单个 html 页面中拥有多个选项卡,但我的代码无法正常工作

jquery - 使用 jquery.on ('click' 时 iPhone 上的元素闪烁

jQuery 模板引擎

javascript - 可排序列表不会排序(jQuery/Javascript)

javascript - 循环模板无法处理 ie11 中的数组

javascript - A* 在 Canvas 上寻路

javascript - 部分边框颜色

javascript - 我需要使用 javascript 在 html 表单中创建一个图像元素及其所有属性,我该怎么做?

php - 将 css 文件链接到同一目录中的多个 php 文件的两种不同方法