npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-jsrender

v1.0.9

Published

A wrapper for the jsrender project by @borismoore. However, this wrapper is no longer needed, since JsRender now natively provides full integration and extended functionality for Node.js, Express, Hapi and Browserify

Downloads

53

Readme

Node-JSRender

!!! UPDATE 5th Feb 2016: Boris Moore (the creator of jsrender) recently released a new official jsrender version (https://www.npmjs.com/package/jsrender) that includes full support for Node.js and Browserify. This node-jsrender wrapper package is therefore no longer needed. Please use the official jsrender package, directly, instead:

npm install jsrender

The official package github repo is available here: https://github.com/BorisMoore/jsrender

This project will no longer be actively maintained.

PREVIOUS README CONTENTS

An ~~actively maintained~~ wrapper for the jsrender project by @borismoore (https://github.com/BorisMoore/jsrender). Uses latest source from the jsrender project and extends functionality for easy use in Node.js.

Install

PLEASE SEE NOTE ABOVE - THIS LIBRARY IS NO LONGER MAINTAINED AND HAS BEEN REPLACED

npm install node-jsrender

Using With Express

If you use express and wish to use jsRender as your express template engine you can now do so. You can specify the engine to use via:

var express = require('express');
var app = express();
var nodeJsRender = require('node-jsrender');

// Register jsRender with express to handle html files
nodeJsRender.express('html', app);

// Set express template engine to jsrender
app.set('view engine', 'html');

Usage Without Express (Manually Rendering)

Loading a Template From a String

// Require the node module
var jsrender = require('node-jsrender');

// Load a template from string
jsrender.loadString('#myTemplate', '{{:data}}');

// Render the template with data
jsrender.render['#myTemplate']({data: 'hello'});

// Output is: "hello"

Loading a Template From a File (Synchronously)

// Require the node module
var jsrender = require('node-jsrender');

// Load a template from ./templates/myTemplate.html
//     Contents of ./templates/myTemplate.html is: "{{:data}}"
jsrender.loadFileSync('#myTemplate', './templates/myTemplate.html');

// Render the template with data
jsrender.render['#myTemplate']({data: 'hello'});

// Output is: "hello"

Loading a Template From a File (Asynchronously)

// Require the node module
var jsrender = require('node-jsrender');

// Load a template from ./templates/myTemplate.html
//     Contents of ./templates/myTemplate.html is: "{{:data}}"
jsrender.loadFile('#myTemplate', './templates/myTemplate.html', function (err, template) {
	if (!err) {
		// Template was loaded
		// Render the template with data
		jsrender.render['#myTemplate']({data: 'hello'});
		
		// Output is: "hello"
	} else {
		throw(err);
	}
});

Nested Templates

In jsrender, you can have templates that reference other templates, nested templates. But to work, you must register the nested templates before rending the parent template.

// Require the node module
var jsrender = require('node-jsrender');

// Load parent template from string
//     {{for items tmpl="#listItem" //}} indicates a nested template
jsrender.loadString('#list', '<ul>Grocery List</ul>{{for items tmpl="#listItem" /}}</ul>');

// Load child template from string
//      Nested templates must be registered with a name matching the parent template before rendering the parent template
jsrender.loadString('#listItem', '<li>{{:name}}</li>');

// Render the parent template with data
jsrender.render['#list']({items: [{name:'Carrots'}, {name: "Banana"}]});

// Output is: "<ul>Grocery List</ul><li>Carrots</li><li>Banana</li></ul>"