- HtmlWidget html widgets used as (template) plugins and/or standalone for PHP, Node/XPCOM/JS, Python both client and server-side (can be used as plugins for Contemplate)
- Tao A simple, tiny, isomorphic, precise and fast template engine for handling both string and live dom based templates
- ModelView MVC jQueryUI Widgets plug-n-play, state-full, full-MVC widgets for jQueryUI using modelview.js (e.g calendars, datepickers, colorpickers, tables/grids, etc..) (in progress)
- Importer simple class & dependency manager and loader for PHP, Node/XPCOM/JS, Python
- PublishSubscribe a simple and flexible publish-subscribe pattern implementation for Node/XPCOM/JS, PHP, Python, ActionScript
- Dromeo a flexible, agnostic router for Node/XPCOM/JS, PHP, Python, ActionScript
- Dialect a simple cross-platform SQL construction for PHP, Python, Node/XPCOM/JS, ActionScript
- Xpresion a simple and flexible eXpression parser engine (with custom functions and variables support) for PHP, Python, Node/XPCOM/JS, ActionScript
- Regex Analyzer/Composer Regular Expression Analyzer and Composer for Node/XPCOM/JS, PHP, Python, ActionScript
- RegExpX powerful and versatile pattern matching for Node/JS (in progress)
- DateX eXtended & localised Date parsing, diffing, formatting and validation for Node/XPCOM/JS, Python, PHP, ActionScript
- Abacus a fast combinatorics and computation library for Node/JS, PHP, Python
There are a couple of other frameworks named also
- There is an older and quite different template engine for node named also
"contemplate"here and here
This repository and project is completely unrelated to these frameworks.
(it seems the word contemplate is nice for a template engine :) )
- Online Example
- API Reference
If you use
Contemplate in your application and you want to share it, feel free to submit an example link
There are many templating engines out there, which are elegant, fast, multipurpose and so on.. Most of the sophisticated engines use a custom parser (and usually a full-fledged framework) to build the engine.
This is highly versatile:
but can have performance issues sometimes
and / or requires to learn a (completely) new syntax for building a template.
These drawbacks can be compensated if one uses
PHP itself as templating engine.
PHP already IS a templating language and a very fast at it.
This can create very simple, intuitive and fast templates.
The drawbacks of this approach are:
It works only with
PHP, and many times the same template needs to be used also by
It can be cumbersome to combine or iterate over templates and parts.
Contemplate seeks to find the best balance between these requirements.
The solution is inspired by John Resig's post (see above) and the fact that
Contemplatedoes a minimum parsing (and caching) in order to create dynamic templates and trying to contain the needed functionality inside the common language subset(s).
Most of the time this can be accomplished, the rest functionality is built with custom functions which mostly resemble the
PHPsyntax, yet work the same in all the engine's implementations.
Simple and light-weight ( only one relatively small class for each implementation, no other dependencies )
Fast , can cache templates dynamically (filesystem caching has 3 modes,
NONEwhich uses only in-memory caching,
NOUPDATEwhich caches the templates only once and
AUTOUPDATEwhich re-creates the cached template if original template has changed, useful for debugging)
UMDmodules which can be used in both
Syntax close to
PHP(there was an effort to keep the engine syntax as close to
PHPsyntax as possible, to avoid learning another language syntax)
Easily extensible , configurable
Object-oriented , templates implement inheritance and polymorphism in an almost full object-oriented manner (see below)
Supports multiple dynamic contexts , and contextual settings so that different modules of an application can use the engine independantly (see examples and manual)
Localization , Pluralisation , Date formatting built-in and configurable easily ( simple Data escaping is also supported)
Date manipulation similar to
datefunction). An extended, localized version of
php's date function
ldateis also implemented in the framework
Loops can have optional
elseforstatement when no data, or data is empty (see tests)
includeother templates (similar to
includedirective), these includes wil be compiled into the the template that called them
Templates can call another template using
tplfunction, these templates are called as templates subroutines and parsed by themselves
Templates and template functions can also have inline templates as parameters via
Template Inheritance , templates can extend/inherit other templates using
extendsdirective and override blocks using
endblockdirectives (see examples)
Direct Super reference , templates can use the
supertemplate function to directly reference (and call) a super block if needed in OO manner (see examples)
Nested Blocks , template
blockscan be nested and repeated in multiple ways (see examples)
Custom Plugins , can be used as template functions to enhance/extend the engine functionality (see examples)
custom plugins can be also inlined, i.e their code can be expanded at compile-time using
Contemplate::inlinetemplates in their definition, e.g saving unnecessary look-ups at render-time (see examples)
- Only 3 classes are used (
Contemplate.py), no other dependencies
- all major browsers
- add support for multiple
contexts(which include separate
cachedirectories and related parameters) so that the engine can be used in same application by different modules independantly [DONE]
- simplify template
pluginsnotation by eliminating the
%prefix (compatibility mode to older versions also supported) [DONE]
- support asynchronous template loading/rendering for
ActionScript, Perl, Java, Scala[TODO?]
PHP) into a
Contemplate(for node) into standalone executable (eg. https://github.com/crcn/nexe) [TODO?]
- keep-up with
python, browsers updates
Note: The engines included in the (following) tests, have different philosophy and in general provide different features. These are only illustrative modulo all the other features.
The following tests were made on a revision of a 2013 jsperf test for
kendoui template engines. More tests should be done.
0.6.5) was 2nd place on Firefox and 3rd (or close) place on Opera, IE, while
Contemplate was average to slower on Chrome. The reason was mostly that
Contemplate was using a code to copy/isolate the input data every time inside the render function, which most of the time is redundant, else user can use the
Contemplate.data method to create a shallow copy suitable to be used as render data. So this was removed, plus some minor refactoring and minor loop optimisation.
This resulted in great performance increase as shown below. (see changelog)
1.0.0) is (consistently) near 1st place on all browsers.
Parse / Compilation Time
The following tests involve
mustache template engines. More tests should be done.
1.0.0) is (consistently) 1st place on all browsers.
/tests folder, to test the basic functionality