下面的例子显示了这一过程。咱们使用 name = "myParagraph"属性建立一个模板。咱们的 template 标签body元素下方建立,但须要包括它在屏幕渲染显示以前。咱们也能够使用 {{> myParagraph}} 语法. 在模板中咱们使用的是双大括号 ({{text}}). 这就是所谓的 meteor 模板Spacebars 语言。html
在 JavaScript文件咱们设置 Template.myParagraph.helpers({}) 方法是对模板链接。咱们只在本示例中使用 text 助手。数组
<head> <title>meteorApp</title> </head> <body> <h1>Header</h1> {{> myParagraph}} </body> <template name = "myParagraph"> <p>{{text}}</p> </template>
在 JavaScript文件咱们设置 Template.myParagraph.helpers({}) 方法是对模板链接。咱们只在本示例中使用 text 助手。浏览器
import { Template } from 'meteor/templating'; Template.myParagraph.helpers({ text: 'This is paragraph...' });咱们保存更改以后,打开浏览器会获得下面的输出 -
在这个例子中,咱们使用的是 {{#each paragraphs}} 遍历数组 paragraphs,并返回模板 name = "paragraph" 遍历每一个值 。ui
<head> <title>meteorApp</title> </head> <body> <div> {{#each paragraphs}} {{> paragraph}} {{/each}} </div> </body> <template name = "paragraph"> <p>{{text}}</p> </template>
这里咱们须要建立 paragraphs 助手. 这是有五个文本值的数组。code
// This code only runs on the client import { Template } from 'meteor/templating'; Template.body.helpers({ paragraphs: [ { text: "This is paragraph 1..." }, { text: "This is paragraph 2..." }, { text: "This is paragraph 3..." }, { text: "This is paragraph 4..." }, { text: "This is paragraph 5..." } ] });如今咱们能够在屏幕上看到五个段落。