• Stars
    star
    264
  • Rank 155,103 (Top 4 %)
  • Language
    JavaScript
  • Created about 10 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Server Side Rendering for Meteor

Build Status

Server Side Rendering for Meteor

Now, you can render Blaze templates on the server very easily. And also, you can assign helpers for templates in the server as well.

Previously, this package loads all the client side templates when your app starts. But now meteor don't allow us to do that. So that behaviour has been removed.

Installation

meteor add meteorhacks:ssr

Usage

This package only works on the server

First create templates and helpers

SSR.compileTemplate('emailText', 'Hello {{username}}, <br> Now time is: {{time}}');

Template.emailText.helpers({
  time: function() {
    return new Date().toString();
  }
});

Then you can render above template anywhere in your app.(only on server)

Meteor.methods({
  sendEmail: function() {
    var html = SSR.render("emailText", {username: "arunoda"});
    console.log(html);
  }
});

Better way to load templates

It's not a good idea to write template(html) inside javascript. So, we can use following approach.

Write your html content inside the private directory.

<!-- file: private/hello.html -->
Hello {{username}}, <br>
Now time is: {{time}}

Then load it like this:

SSR.compileTemplate('emailText', Assets.getText('hello.html'));

Template.emailText.helpers({
  time: function() {
    return new Date().toString();
  }
});

You can render the template as previously.

API

SSR.render(template, data)

You can render a template with data. For template argument you can either pass the name of the template or the actual template instance itself.

SSR.compileTemplate(templateName, stringTemplateContent, [options])

You can use this API to compile templates in the server. The options parameter allows you to choose the template language with the language option.

If not provided this default to html which is handled by the spacebars compiler. You can also use jade as another option β€” and in this case you need to add following package:

meteor add mquandalle:jade

Note: the order in which you add jade and SSR matters! First add jade as a dependency and then SSR, otherwise the jade-compiler can not be located by Meteor.

What can we do with SSR

Since, this is full Blaze on the server, you can have sub-templates, dynamic templates and all the awesome features of Blaze. These are the few things you can do with SSR.

  • Render HTML pages for SEO bots
  • Render HTML pages for some of your routes (you may need to serve html yourself)
  • Build SEO aware static sites
  • Handy email templates with Blaze

Wow, How you did this

Actually, most of the stuff has been already done by Meteor, so kudos to Meteor team.

  • This also, adds some patches to Blaze.
  • Finally, this package comes with a clean and nice API to render templates.

More Repositories

1

cluster

Clustering solution for Meteor with load balancing and service discovery
JavaScript
631
star
2

npm

Complete NPM integration for Meteor
JavaScript
508
star
3

meteord

MeteorD - Docker Runtime for Meteor Apps for Production Deployments
Shell
439
star
4

sikka

Sikka - A Firewall for Meteor Apps
JavaScript
258
star
5

kadira

Performance Monitoring for Meteor
JavaScript
217
star
6

meteor-aggregate

Proper MongoDB aggregations support for Meteor
JavaScript
189
star
7

picker

Server Side Router for Meteor
JavaScript
182
star
8

meteor-down

Load testing for Meteor
JavaScript
175
star
9

search-source

Reactive Data Source for Search
JavaScript
146
star
10

flow-components

Build your Meteor app with Components.
JavaScript
132
star
11

unblock

this.unblock inside publications :D
JavaScript
87
star
12

meteor-inject-initial

Allow injection of arbitrary data to initial Meteor HTML page
JavaScript
80
star
13

meteor-async

Set of async utilities to work with NPM modules inside Meteor
JavaScript
63
star
14

goddp

DDP Server implemented with golang
Go
47
star
15

meteorx

Exposing some of the internal Meteor API prototypes
JavaScript
41
star
16

mup-frontend-server

Frontend Server for Meteor Up
Nginx
37
star
17

kube-init

Easiest way to deploy a Kubernetes Cluster to learn Kubernetes
Shell
34
star
18

zones

Zone.js integration for meteor
JavaScript
30
star
19

meteorhacks.github.io

MeteorHacks Website
HTML
29
star
20

hyperkube

Hyperkube
Shell
20
star
21

inject-data

A way to inject data to the client with initial HTML
JavaScript
18
star
22

kadira-profiler

CPU Profiling support for Kadira
JavaScript
14
star
23

bddp

DDP like binary protocol implemented using cap'n proto
Go
12
star
24

repeeet

making repeeet tweeting super simple
JavaScript
11
star
25

code-standards

Code Standards for MeteorHacks projects
9
star
26

js-pipes

MongoDB aggregation pipeline implementation in JavaScript
JavaScript
9
star
27

meteor-customer-io

Customer.io Integration for Meteor
JavaScript
9
star
28

cluster-performance

Performance Test for Cluster
JavaScript
8
star
29

docker-librato

Forward all stats from all running docker containers to Librato
JavaScript
8
star
30

kdb

ACID High Performance Time Series DB for any kind of storage - No it isn't
Go
7
star
31

meteor-todo-app

Simple Todo App with Meteor
JavaScript
5
star
32

gocluster

Meteor Cluster protocol implemented for Go
Go
4
star
33

meteor-collection-utils

Expose some underline collection apis
JavaScript
4
star
34

find-faster-chat-demo

Simple Chat To Demo Meteor Fast Finder Use
JavaScript
3
star
35

ddptest

Test DDP servers
JavaScript
3
star
36

zones-simple-example

Simple Example Meteor App with Zones
JavaScript
2
star
37

mongo-search

Simple API to use MongoDB Full Text search with Meteor
2
star
38

kmdb

metric database powered by kdb
Go
2
star
39

meteor-down-backdoor

Backdoor Meteor package for MeteorDown
JavaScript
2
star
40

kadira-binary-deps

Binary Dependencies for Kadira
JavaScript
2
star
41

simple-rpc-go

A really simple and fast binary RPC middleware
Go
2
star
42

kmdb-node

NodeJS client for kmdb
JavaScript
2
star
43

nsqd-to-librato

Send NSQ stats to librato
JavaScript
2
star
44

lean-components-example

lean-components-example
JavaScript
2
star
45

meteor-zone-example

Example meteor app for meteor-zone package
JavaScript
1
star
46

node-histo-utils

A set of utilities to create, merge and manage histograms
JavaScript
1
star
47

blaze-ext

Create blaze templates with .blaze extension
1
star