下面的例子顯示了這一過程。咱們使用 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..." } ] });如今咱們能夠在屏幕上看到五個段落。