Cookie Notice

As far as I know, and as far as I remember, nothing in this page does anything with Cookies.
Showing posts with label templating. Show all posts
Showing posts with label templating. Show all posts

2015/04/16

Template vs Text::Handlebars

A previous attempt at supporting Handlebars
In the comments of Where To Generate the HTML?, Tom Molesworth points out that, if you're going to be having a template that generates both on the client and server side, having two templates instead of one leads to more maintenance work.

This is most certainly true. In that case, it was just enough code to demonstrate a problem, not something I would expect to maintain. In fact, if users who weren't me were regularly finding that code, I'd be more more likely to delete it than support it. But the broader point; that there are things that I might create on the server side, then regenerate on the client side, and as I do more and more web work, I become more and more likely to want to do that.

Below I show the creation of the table and the creation of output in both Template Toolkit and Text::Handlebars. You will notice that you have a handle for each element in TT ( FOREACH row IN table being akin to for my $row ( @table ) ), while with Handlebars, you get this. The joke about JavaScript is that you want to throw up your hands and scream "this is B.S.!" but you're not sure what this is.

On the other hand, I've always been proud of making good, well-formatted HTML, and I do not like the formatting of the table that TT created. I've tried to make TT format more like I want it to look, and generally I just give up and make sure that it has everything my users, my code and I need of it instead. The Handlebars-generated HTML is exactly like I'd want my code to look.

Plus, Handlebars is cross-platform. I understand there's Jemplates to handle TT in Javascript, so strictly speaking, both are.

So, there's the code and the the rendered output. What do you think? What's your preference?

2012/08/02

I think Pure.js is out of the running

I have been on the lookout for a templating engine for Javascript. Thanks to the great outpouring of suggestions, I have a number of suggested libraries to test.

And first in the running was Pure.js. There is something to it, and it sounds like the author of the library, BeeBole, is a good programmer with an active user base, and he did try to be helpful to me, sending me this link to where he pulled templates from other pages.

If I could rewrite prompt() such that used a textarea equivalent rather than a popup with input type="text", I'd probably toss the whole thing. But, as this is what I'm looking for, my desire is for a solution that could work on a page that looked like <body></body> and what I see of pure.js is that it is much more aligned with replacing values it finds within existing structures.

I'm thankful for his help, but I'm off to try moustache.js.