Icontem

stpl: Template engine based on replacing tags

Recommend this page to a friend!
  Info   View files View files (10)   DownloadInstall with Composer Download .zip   Reputation   Support forum (2)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2016-05-21 (5 months ago) RSS 2.0 feedNot enough user ratingsTotal: 165 All time: 283 This week: 29Up
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
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  
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  /  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:165
This week:0
All time:283
This week:29Up