stpl: Template engine based on replacing tags

Recommend this page to a friend!
     
  Info   View files Files   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 173 All time: 301 This week: 6Up
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: 48
All time rank: 262 in France France
Week rank: 6 Up2 in France France Equal
Innovation award
Innovation award
Nominee: 5x

Winner: 3x

Details

stpl ==== 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}}`` - even using alias ``{{#elements as elmt}}<li>{{elmt.propname}}</li>{{/elements}}`` - support dotted notation ``{{childs.length}}`` - even back reference ``{{../propName}} - can even include sub templates ``{{>subTemplateName}}`` - filtering properties dynamicly ``{{firstname|ucFirst}}`` - including builtin filters: empty, jsonEncode, lowerCase, ucFirst, upperCase, nl2br ## 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 (10)  
File Role Description
Files folder imagelib (2 files)
Files folder imagetests (3 files)
Accessible without login Plain text file bower.json Data Auxiliary data
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 (10)  /  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 (10)  /  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:173
This week:0
All time:301
This week:6Up