richmarr / sizlate

use sizzle selectors for express.js templating

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sizlate

Sizlate is an HTML templating engine for Express.js.

Sizlate requires NO special syntax, your templates only contain valid HTML.

Templates are populated using sizzle selectors (as used in jQuery).

Install

npm install sizlate

Examples

Simple text example


	app.get('/', function(req, res) {
		res.render('home', {
			selectors: {
				'a': 'hi there'
			}
		});
	});

See /examples/basic
  • Note that the text in the template is overridden. This allows you to pre-populate a design templates with dummy data.
  • Please also note that the template should only have one root html element. This is a known issue.

Populating a node using a javascript object


	app.get('/', function(req, res) {
		res.render('home', {
			selectors: {
				'a': {
					href: 'http://yahoo.com',
					title: 'yahoo',
					innerHTML: 'yahoo'
				}
			}
		});
	});

See /examples/object

All these values will override the existing value except className which will be added on to the end of any existing classes.

Partial Example

With partials if you do not specify a class name for the keys in the data the keys will be converted into a class.


	app.get('/', function(req, res) {
		res.render('home', {
			selectors: {
				'ul#list': {
					partial: 'part',
					data: [
						{
							name: 'bob'
						},
						{
							name: 'anna'
						}
					]
				}
			}
		});
	});



	app.listen(8000);
	console.log('check out http://localhost:8000');

See /examples/partial

  • If no data is passed in the partial will render without any data
  • If an empty array is passed into data the partial will not be displayed at all.

The template is inserted into a div with an id of container (#container) in layout.html.

See the examples folder for more examples.

Requires express.js and node.js.

Express 3.0 Changes with Sizlate 0.7.0

All template files must use .sizlate extension. (if someone can fix I would happily go back to .html)

Do not specify file extensions for templates or partials. Examples have all been updated.

Its now using Cheerio instead of JSOM which should make things much faster.

Other than the changes mentioned above the API should remain the same.

Any problems please create an issue.

About

use sizzle selectors for express.js templating


Languages

Language:JavaScript 100.0%