stpl: Template engine based on replacing tags

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Info   View files View files (9)   DownloadInstall with Composer Download .zip   Reputation   Support forum (2)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings  
2014-02-03 (2 years ago) RSS 2.0 feedNot enough user ratingsTotal: 164 All time: 272 This week: 24Up
Version License JavaScript version Categories  
stpl 1.0MIT/X Consortium ...1.0Templates
Description Author  

This object implements a template engine based on replacing tags.

It can search for tags with variable names enclosed within two sets of curly braces and replaces them with assigned variable values.

The object supports escaping tags using an additional set of curly braces, conditional variable replacement, iteration through a list of values, can use the dot notation for object values, including sub-templates, filters for variable values, etc..

Picture of Jonathan Gotti
  Performance   Level  
Name: Jonathan Gotti <contact>
Classes: 8 packages by
Country: France France
Age: 39
All time rank: 272 in France France
Week rank: 50 Down4 in France France Down
Innovation award
Innovation award
Nominee: 5x

Winner: 3x


really lightweight and simple javascript template system
[![Build Status](https://travis-ci.org/malko/stpl.png?branch=master)](https://travis-ci.org/malko/stpl)

##supported syntax:

 - single variable parameters: ``{{varname}}``
 - escaped single variable parameters: ``{{{varname}}}``
 - if syntax: ``{{varname?}}varname as a value{{?varname}}``
 - if not syntax ``{{varname!?}}varname as a value{{?varname}}``
 - loop through each elements ``{{#elements}}<li>{{propname}}</li>{{/elements}}``
 - support dotted notation ``{{childs.length}}``
 - can even include sub templates ``{{>subTemplateName}}``
 - filtering properties dynamicly ``{{firstname|ucFirst}}``

## methods:
 - stpl.registerScriptTag(DOMelment scriptTag,[String name (default to rel attribute value)]) register the content of a script type="text/stpl" as a template string
 - stpl.registerString(String name, String templateString) register a string as a template
 - stpl.registerFilter(String name,Function filter) register a filter any global function can be used as a filter without being previously registered
 - stpl.preload() preload all script tags with type="text/stpl" as template string using their rel attribute as name.
 - stpl.renderString(String templateString,Object datas,Object context) render the given template string using given datas. A context may be passed ans will be used for accessing parent properties for example
 - stpl(String templateName, Object datas) will render previously registered template string with given datas
  Files folder image Files  
File Role Description
Files folder imagelib (2 files)
Files folder imagetests (3 files)
Accessible without login Plain text file gruntfile.js Conf. Configuration script
Accessible without login Plain text file LICENCE.TXT Doc. Documentation
Accessible without login Plain text file package.json Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  lib  
File Role Description
  Plain text file stpl.js Class Class source
  Plain text file stpl.min.js Class Class source

  Files folder image Files  /  tests  
File Role Description
  Accessible without login Plain text file qunit-1.11.0.css Doc. Documentation
  Accessible without login Plain text file qunit-1.11.0.js Test Unit test script
  Accessible without login HTML file test-stepl.html Doc. test

 Version Control Unique User Downloads Download Rankings  
 100%Total:164All time:272
 This week:0This week:24Up