Meteor Blaze - Meteor

What is the use of Blaze package in Meteor?

Blaze is Meteor package which is used for building live reactive templates.

Render Method

Rendor method is used to render templates into DOM. First create myNewTemplate which will be rendered. Then add myContainer which will be used as a parent element, so that the render method knows where to render our template.

meteorApp.html

Next create a render function which takes two arguments. First one is a template which will be rendered and the second one is parent element which is mentioned above.

meteorApp.js

meteor-blaze-render

Render With Data

If some data has to be passed reactively, use renderWithData method. HTML will be exactly the same as in previous example.

meteorApp.html

You can add your data as a second argument in Meteor.renderWithData method. Other two arguments are the same as in example before. In this example your data is function that will log some text.

meteorApp.js

meteor-blaze-render-with-data

Remove Method

We can add remove

meteorApp.hmtl

In this example a template is rendered which will be removed after three seconds. Notice the Blaze.Remove method that we are using for removing the template.

meteorApp.js

Below table shows other methods that can be used.

S.No.

Method & Details

1

Blaze.getData([elementOrView])

Used to retrieve data from the rendering element.

2

Blaze.toHTML(templateOrView)

Used to render templates or views to string.

3

Blaze.toHTMLWithData(templateOrView, data)

Used to render templates or views to string with additional data.

4

new Blaze.View([name], renderFunction)

Used to create new Blaze reactive part of the DOM.

5

Blaze.currentView

Used to get the current view.

6

Blaze.getView([element])

Used to get the current view.

7

Blaze.With(data, contentFunc)

Used to construct a view which renders some content with context.

8

Blaze.If(conditionFunc, contentFunc, [elseFunc])

Used to construct a view that renders some conditional content.

9

Blaze.Unless(conditionFunc, contentFunc, [elseFunc])

Used to construct a view that renders some conditional content (inverted Blaze.if).

10

Blaze.Each(argFunc, contentFunc, [elseFunc])

Used to construct a view that renders contentFunct for every item.

11

new Blaze.Template([viewName], renderFunction)

Used to construct new Blaze view with name and content.

12

Blaze.isTemplate(value)

Used to return true if value is a template object.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Meteor Topics