Yet Another JavaScript Template Engine
I had to do this. :-)
I mean, I don't like any existing template systems.
I don't like mine either. But still I think it's better than others. I was looking at Tenjin and they have something like this:
<?js for (var i = 0; i < list.length; ++i) { ?> <?js var el = list[i] ?> <li>#{el}</li> <?js } ?>
Functional, maybe, but downright ugly. In YAJET, we can write it like this:
$(FOREACH (el => list) <li>$el</li> $)
which I think is a lot better. YAJET compiles the templates into JavaScript code, so for your template you get a function that runs blazing fast. It tries hard to do this The Right Way, so you don't have weird variable name clashes, or side effects.
Give it a try. There's a jQuery plugin too, for those who can't live without jQuery. :-)
Comments — add your comment
John Resig himself came up with a very neat micro js template engine. Should worth a try.
http://ejohn.org/blog/javascript-micro-templ…
There's also my Mold lib (http://marijn.haverbeke.nl/mold/), which has just as clean a syntax, but is more clever about scope (having template code close over the right variables, allowing access to created nodes by the template, and easy event hanlder registration).
Yep, I knew this one. It's small and fast -- good stuff, like all your work! :-)
I just had my own ideas about the syntax (Yajet differs quite a lot) and needed the ability to define reusable template blocks (AFAIK Mold lacks this). And it's always more fun when you do it yourself. :)
> reusable template blocks (AFAIK Mold lacks this)
Yeah, you'd make them separate templates. I know what you mean about doing things yourself being the most fun, though.
Hi, I have also started a new open source project to offer an alternative way to js template engine. Please check www.tog2html.com. :)