Meaning of Yoga in Indian Philosophy (wikipedia)
("unifying through yoga, contemplate and attain mastery")
tico a tiny, super-simple MVC framework for PHP
This started as a a __proof-of-concept__ but developed into a __full-blown and versatile__ template engine.
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.
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 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
`Contemplate` does 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 `PHP` syntax, 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 ) `~50kB` minified, `~16kB` zipped
__Fast__ , can cache templates dynamically (filesystem caching has 3 modes, `NONE` which uses only in-memory caching, `NOUPDATE` which caches the templates only once and `AUTOUPDATE` which re-creates the cached template if original template has changed, useful for debugging)
UMD modules which can be used in both `node.js`/`AMD`/`XPCOM`/`browser`/`es6 module fallback`)
Syntax __close to `PHP`__ (there was an effort to keep the engine syntax as close to `PHP` syntax as possible, to avoid learning another language syntax)
Easily __extensible__ , __configurable__
__Object-oriented__ , templates implement inheritance and polymorphism in a 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)
`X-GetText` / `POEdit` translation-friendly localisation (keywords: `locale`, `xlocale:1,2c`, `nlocale:2`, `nlocale:3`, `nxlocale:2,4c`, `nxlocale:3,4c`)
__Date manipulation__ similar to `PHP` format (ie `date` function). An extended, localized version of `php`'s date function `ldate` is also implemented in the framework
Loops can have optional `elsefor` statement when no data, or data is empty (see tests)
Templates can `include` other templates (similar to `PHP` `include` directive), these includes wil be compiled into the the template that called them
Templates can call another template using `tpl` function, these templates are called as templates subroutines and parsed by themselves
Templates and template functions can also have inline templates as parameters via `inline` template function
__Template Inheritance__ , templates can extend/inherit other templates using `extends` directive and override blocks using `block` , `endblock` directives (see examples)
__Direct Super reference__ , templates can use the `super` template function to directly reference (and call) a super block if needed in OO manner (see examples)
__Nested Blocks__ , template
blocks can 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::inline` templates in their definition, e.g saving unnecessary look-ups at render-time (see examples)
Only 3 classes are used (`Contemplate.php`, `Contemplate.js`, `Contemplate.py`), no other dependencies
`PHP` `5.2+` supported
`Node` `0.8+` supported
`Python` `2.x` or `3.x` supported
add support for multiple `contexts` (which include separate `templates`, `cache` directories and related parameters) so that the engine can be used in same application by different modules independantly [DONE]
simplify template `directives`, `functions` and `plugins` notation by eliminating the `%` prefix (compatibility mode to older versions also supported) [DONE]
support asynchronous template loading/parsing/rendering/writing for `node/browser` [DONE]
add `Contemplate` implementations for `ActionScript, Perl, Java, Scala` [TODO?]
transform `Contemplate` (for `PHP`) into a `PHP` `C`-extension, `Contemplate` (for node) into standalone executable (eg. https://github.com/crcn/nexe) [TODO?]
keep-up with `php`, `node`, `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)
Previous tests are here jsperf/0.6.5, jsperf/0.6.7, jsperf/0.7, jsperf/0.7.1, jsperf/0.8, jsperf/0.8.1,
jsperf/1.0.0 (1.0.0+ format)
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.
Previous tests are here jsperf/0.6.7, jsperf/0.7, jsperf/0.7.1, jsperf/0.8, jsperf/0.8.1,
1.0.0) is (consistently) 1st place on all browsers.
/tests folder, to test the basic functionality
Sample Template markup
Data to be used for the template