Hello,
No matter what delimiter we pick the parsing performance and generated code will remain the same as long as we keep it simple - no {{each, no {{ /if }} etc.
Razor-like syntax looks great but the Razor view engine will try to evaluate it as well (server-side) which is why we must not use a delimiter used in server template engines in the wild (this is the reason <%= %> is out of the question as well).
Here is my comment on every option:
<ul>
{{ kendo.each(items, function(item){ <li> {{item}} </li> }) }}
</ul>
Not sure we can parse that as there is nesting of {{ . We need a full blown parser with grammar to be able to parse this properly which is perhaps out of scope.
<ul>
<# for (var item in items) { #>
<li> <# item #>
<# } #>
</ul>
The current somewhat ugly option. Picking a better looking delimiter here would help. Mustaches {{ have the drawback of being a JavaScript special symbol and too many mustaches hurt the eyes too. If we want to keep the templates JavaScript like we better find an alternative delimiter.
<ul>
{{each(item, items)}}
<li>{{item}}</li>
{{ /each }}
</ul>
jQuery Templates like solution (the latter uses {{=item}} instead of {{item}} ). The thing I don't like is the closing tags. I find them awkward but heck every existing engine seems to use them. Not sure if this allows arbitrary JavaScript code though.
<ul>
@foreach(var item in items){
<li>@item</li>
}
</ul>
This won't work in an ASP.NET MVC Razor view page as Razor will pick it up and try to parse it.
The way I see it we have two options:
- Find a better looking delimiter which satisfies this regexp: [^{%#@]. We need three flavors
- for embedding arbitrary JavaScript expressions
- for emitting raw values
- for emitting html encoded values
- Pick the mustaches as delimiter and implement the {{each}} {{/each}} pattern to avoid using single { in the template definition. Keep the current support for arbitrary JavaScript (if at all possible).
I hope this makes sense!
Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework -
download Kendo UI now!