[Helma-user] Javascript Template Engine, Sub Templates
Juerg Lehni
juerg at scratchdisk.com
Wed Nov 8 02:30:45 CET 2006
I added the possibility of sub templates to my template engine today,
as a proof of concept:
http://dev.helma.org/Wiki/JavaScript+Template+Engine/
The syntax and naming is not fixed, but so far it works well for me,
so I thought I should share it.
This also had the side-effect that templates can now be created from
strings like this:
new Template(str);
I think it should be very easy to create a JS only version from the
current code that could run on the client side.
One discussion that is still open is the problem with closing tags
for nested content (</%>). In my email from 27.10.06 that remained
unreplied so far I wrote about this, among many other open template
questions:
http://grazia.helma.at/pipermail/helma-dev/2006-October/003166.html
- Nested content: So far it has been said they should use <% end %>
instead of </%> as the end tag, for more consistency. I just realized
today why this is not as easy as we hoped, and why I have come up
with the current scheme. Look for example at this situation:
<% foreach (value in list) %>
<% value.macro %>
Some HTML
<% end %>
It would be good to hear reactions about this problem, and also about
the other questions in my post.
Bellow some examples of sub templates. Comments are welcome.
Jürg
---
Definition:
<% template "name">
This is a sub-template. It can call <% macros %> and write <%=
param.value %> too!
</%>
Rendering:
<% render "name" value="variables" %>
Rendering of normal templates:
<% this.render "name" foo="bar" %>
Definition and rendering into a variable in one command:
<% set "text">
Render this text into 'name'. <% macros %> can be called.
</%>
This can now be used like a normal variable, and for example be
passed as
the default value in another macro:
<%= text %>
<% do_something default=text %>
More information about the Helma-user
mailing list