All Projects → dburles → meteor-spacebars-tohtml

dburles / meteor-spacebars-tohtml

Licence: MIT License
Meteor package to ease rendering spacebars to html

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to meteor-spacebars-tohtml

meteor-reactive-mongo
Reactive server-side MongoDB queries
Stars: ✭ 14 (-60%)
Mutual labels:  meteor, meteor-package
meteor-flow-router-map
Meteor package for Flow Router
Stars: ✭ 15 (-57.14%)
Mutual labels:  meteor, meteor-package
Meteor-Mailer
📮 Bulletproof email queue on top of NodeMailer with support of multiple clusters and servers setup
Stars: ✭ 21 (-40%)
Mutual labels:  meteor, meteor-package
meteor-server-autorun
Server-side Tracker.autorun
Stars: ✭ 36 (+2.86%)
Mutual labels:  meteor, meteor-package
Meteor-logger
🧾 Meteor isomorphic logger. Store application logs in File (FS), MongoDB, or print in Console
Stars: ✭ 51 (+45.71%)
Mutual labels:  meteor, meteor-package
Meteor-logger-file
🔖 Meteor Logging: Store application log messages into file (FS)
Stars: ✭ 24 (-31.43%)
Mutual labels:  meteor, meteor-package
hypersubs
an upgraded version of Meteor subscribe, which helps optimize data and performance!
Stars: ✭ 13 (-62.86%)
Mutual labels:  meteor, meteor-package
Meteor-Cookies
🍪 Isomorphic bulletproof cookie functions for client and server
Stars: ✭ 41 (+17.14%)
Mutual labels:  meteor, meteor-package
flow-router
🚦 Carefully extended flow-router for Meteor
Stars: ✭ 191 (+445.71%)
Mutual labels:  meteor, meteor-package
Meteor-flow-router-title
Change document.title on the fly within flow-router
Stars: ✭ 23 (-34.29%)
Mutual labels:  meteor, meteor-package
svelte-meteor-data
Reactively track Meteor data inside Svelte components
Stars: ✭ 14 (-60%)
Mutual labels:  meteor, meteor-package
meteor-control-mergebox
Control mergebox of publish endpoints
Stars: ✭ 28 (-20%)
Mutual labels:  meteor, meteor-package
Client-Storage
🗄 Bulletproof persistent Client storage, works with disabled Cookies and/or localStorage
Stars: ✭ 15 (-57.14%)
Mutual labels:  meteor, meteor-package
meteor-two-factor
🔐 Two factor authentication package for accounts-password
Stars: ✭ 80 (+128.57%)
Mutual labels:  meteor, meteor-package
meteor-subscription-scope
Scope queries on collections to subscriptions
Stars: ✭ 20 (-42.86%)
Mutual labels:  meteor, meteor-package
Meteor-logger-mongo
🍃 Meteor Logging: Store application log messages in MongoDB
Stars: ✭ 20 (-42.86%)
Mutual labels:  meteor, meteor-package
meteor-computed-field
Reactively computed field for Meteor
Stars: ✭ 18 (-48.57%)
Mutual labels:  meteor, meteor-package
Meteor-Template-helpers
Template helpers for Session, logical operations and debug
Stars: ✭ 35 (+0%)
Mutual labels:  meteor, meteor-package
ostrio-analytics
📊 Visitor's analytics tracking code for ostr.io service
Stars: ✭ 14 (-60%)
Mutual labels:  meteor, meteor-package
meteor-packages
Client for Meteor Package Server API
Stars: ✭ 14 (-60%)
Mutual labels:  meteor, meteor-package

Meteor Spacebars.toHTML

A simple helper function to assist with rendering spacebars to HTML. Works on both the server and the client.

Installation

$ meteor add dburles:spacebars-tohtml

API

Super basic example

Spacebars.toHTML({ name: 'foo' }, '<p>Hello {{name}}</p>');

Any helpers defined with Template.registerHelper will be rendered just like usual. If you're on the server you'll need to make sure they're not just defined on the client so it can see them.

Rendering templates on the server

We can render templates on the server by creating files within the private directory.

For example, we could create private/example.html and its contents might look like:

<html>
<head>
  <title>Example</title>
</head>
<body>
  <h1>Example</h1>
  
  <p>Hello {{name}} this is just an example!</p>
</body>
</html>

We can then render it using Meteor's Assets API

var html = Spacebars.toHTML({ name: 'foo' }, Assets.getText('example.html'));

This is very useful for sending HTML emails.

Iron Router

We can also serve templates using Iron Router's server side routes.

Here's a simple example:

Router.route('/test', function() {
  // This could also come from a Collection
  var data = { name: 'foo' };
  
  this.response.writeHead(200, { 'Content-Type': 'text/html' });
  this.response.end(Spacebars.toHTML(data, Assets.getText('example.html')));
}, { where: 'server' });

Template inclusion

Server side only

Currently there's no way to pull in templates using the {{> inclusion}} operator, though we can create our own helper to do much the same thing.

Template.registerHelper('include', function(template, data) {
  data = data || {};
  return Spacebars.toHTML(data, Assets.getText(template));
});

and within our template, for example:

<nav>
  {{{include 'navigation.html'}}}
</nav>
...

We can also pass in an optional data context:

<nav>
  {{{include 'navigation.html' navItems}}}
</nav>
...

Note that we use the triple-stash here so the HTML is not escaped.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].