jQuery.tpl

jQuery.tpl

Hi all!

Impressed by micro-template engine written by John Resig, I've been created this templates variant:

Few examples:
  1. // Simple
  2. {% for (var i=0;i<100;i++) { %}
  3. <div id="{%= i %}"></div>
  4. {% } %}

  5. // With shorthands
  6. {%@ func(abc) { %}
  7. {%= abc %}
  8. {% } %}
  9. {% func("hello world!"); %}

  10. // Other features
  11. {%@ button(value) { %}
  12. {%= $('<button>'+value+'</button>').click(function() {
  13. alert(value);
  14. }) %}
  15. {% } %}
  16. {% button("text"); %}
Also this engine can have named templates and can easily call it from other template (see demos).
And my templates can have optional variables, so you won't see errors like: "undefined variable VALUE" (with some restrictions, of course).


Thanks for reading, will be glad to see your opinion here in replies