Skip to content

Commit

Permalink
Update README with Node.js example.
Browse files Browse the repository at this point in the history
  • Loading branch information
Umakant Patil committed Dec 24, 2013
1 parent 86d5aef commit c84973d
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,54 @@
jSmart
======

jSmart is a port of the Smarty Template Engine to Javascript, a JavaScript template library that supports the template [syntax](https://github.com/umakantp/jsmart/wiki/syntax) and all the features (functions, variable modifiers, etc.) of the well-known PHP template engine [Smarty](http://www.smarty.net/).
jSmart is a port of the Smarty Template Engine to Javascript, a JavaScript template library that supports the template [syntax](https://github.com/umakantp/jsmart/wiki/syntax) and all the features (functioens, variable modifiers, etc.) of the well-known PHP template engine [Smarty](http://www.smarty.net/).

jSmart is written entirely in JavaScript, does not have any DOM/DHTML/browser or third-party JavaScript library dependencies and can be run in a web browser as well as a standalone JavaScript interpreter or [CommonJS](http://www.commonjs.org/) environments like [node.js](http://nodejs.org/).

jSmart supports plugin architecture, you can [extend it with custom plugins](https://github.com/umakantp/jsmart/wiki/Create-Plugin): functions, blocks and variable modifiers, [templates inclusion](https://github.com/umakantp/jsmart/wiki/Include-Templates), [templates inheritance](https://github.com/umakantp/jsmart/wiki/Template-Inheritance) and overriding, [caching](https://github.com/umakantp/jsmart/wiki/Caching), [escape HTML](https://github.com/umakantp/jsmart/wiki/escape_html).

jSmart has some limited support of the [PHP Smarty syntax](https://github.com/umakantp/jsmart/wiki/syntax) and allows you to [use the same Smarty templates on both server and client side](https://github.com/umakantp/jsmart/wiki/Smarty-template-in-javascript), for both PHP and Javascript.

### How to use jSmart in Node.js

### A Quick Introduction
1. Install jSmart from NPM Registry

1. Include jSmart library Javascript file in your header (get the current release by cloning this repo)
$ npm install jsmart


2. Create template, use [PHP Smarty syntax](https://github.com/umakantp/jsmart/wiki/syntax). Say demo.tpl

Hello {$name}


3. Now lets read the template and compile it. _jSmart_ object compiles the template.

var fs = require(fs);
require('jsmart');
var tpl = fs.readFileSync('./demo.tpl', {encoding: 'utf-8'});
var compiledTpl = jSmart(tpl);

4. Assign data to the template passing Javascript object to the _fetch_ function. Variable _compiledTpl_ has the compiled template. You can call _fetch_ function as many times with different data.

var fs = require(fs);
require('jsmart');
var tpl = fs.readFileSync('./demo.tpl', {encoding: 'utf-8'});
var compiledTpl = jSmart(tpl);
var output = compiledTpl.fetch({name: 'World'});
console.log(output);

5. Execute the file.

$ node demo.js

6. Result would be.

Hello World


### How to use jSmart in browser

1. Include jSmart library Javascript file in your header.

<html>
<head>
Expand Down

0 comments on commit c84973d

Please sign in to comment.