[Helma-user] New Additions to Template.js
Juerg Lehni
juerg at scratchdisk.com
Mon Apr 16 18:33:29 CEST 2007
Hi Maks,
Thank you for the feedback. It's very appreciated.
> It don't mind the dollar sign syntax and infact think it does make
> things more clearer - but then again I'm also a frequent velocity
> user.
Actually, I like it a lot too. It makes it much clearer which
variables are from the outside (param. / request. / etc.), and which
ones are defined within the template. And I started to use the
possibility of rendering templates directly into variables through <%
$name %> a lot.
> I don't think I would use the prefix / suffix on loops but then
> that's a personal style preference more then anything.
I think it's usefull as it checks wether the loop produced anything
at all, and only adds them if it did. This would otherwise need to be
done with if / else, which is not so nice.
> Being able to access the value of the loop counter would be very
> handy - perhaps you could maek a builtin "counter variabel like
> velocity uses?
This is implemented now, on the base of the variable name, and in a
way that even when you have two nested loops using the same variable
name, it would still produce the expected result. This is how it
works right now. Any suggestions are welcome:
<% foreach $item in param.list %>
<%= $item#index %>
<%= $item#length %>
<%= $item#isFirst %>
<%= $item#isLast %>
<% end %>
No variables are produced that are not needed. In fact, these special
variables are discovered and then replaced with the proper code. Have
a look at parseLoopVariables in the source code to see what I mean.
I have added two more experimental ones, not sure if they are needed:
#even, #odd. I also just noticed they should probably be called
#isEven, #isOdd?
> Also I think it is useful to have functionality to iterate over
> objects (hashs) as well as Arrays, since often I want to didpaly a
> html table or list of values of an object and I don't worry about
> ordering/sorting it.
That's good to know, I will add it again then. #length and #isLast
will not work on these loops though.
> Also Juerg, would it be possible to agree on freezing on a
> particular version of the syntax? as I currently have a project
> underway where I am using JTSL and another about to begin and would
> like to have a 'stable' version on which I could depend on rather
> then having to keep going back and updating my templates.
I understand... But you should also understand that Template.js was
allways there to be a testbed for me to try out templating stuff. As
the old version works for your project, there is actually no real
need to update it, except that if you want to be able to take advante
of the new stuff.
Having said that, I am not intersted in too many changes myself
either, as I have projects based on it too. I just felt the need to
make some changes in the design decisions, and tried to make this
with as little impact on existing templates as possible.
The things that I broke:
- Nested content is gone. No more <% >...</%>. Is that bad? Should it
be back? It wouldn't be hard. As Hannes said, the nested stuff could
be passed in param.nested. The only place I've used this was for sub
templates, and that now works in the Helma way. Which brings us to:
- Sub Templates: Ditto
- Local variable names need to have $ preprended.
Note that although I don't use the parantheses for "foreach", "if",
"elseif" any longer, you still can if you like that syntax better.
That's it for now.
The site is update with new explanations and code.
Jürg
More information about the Helma-user
mailing list