baryshev / ect

Fastest JavaScript template engine with embedded CoffeeScript syntax
http://ectjs.com
MIT License
626 stars 70 forks source link

Callbacks inside templates #89

Closed sapegin closed 5 years ago

sapegin commented 9 years ago

The simplest way I could find is:

<% @site.posts.limit(5).each (post) => if 1: %>
  <%- @someHelper post.title %>
<% end %>

Is there anything better?

baryshev commented 8 years ago

It should work without if 1

<% @site.posts.limit(5).each (post) => : %>
  <%- @someHelper post.title %>
<% end %>
stiff commented 8 years ago

It will run without errors, but not work. It works only for sync functions. You still can't query the cache or database (which seems to be the case in the original comment).

baryshev commented 8 years ago

Yes, ect not support async calls, because it synchronous. For template engine purposes synchronous way gets more speed then asynchronous. But all data need to be prepared before we send it to template engine.

stiff commented 8 years ago

But still the idea to have a callbacks-based (or event better, promises-based) templates is so tempting that I subscribed for this issue just to see if someone comes up with a clever solution for it without hurting performance :)

It possibly can give some throughput improvements too, say while you querying the DB the rest of template which doesn't need it is being rendered.