Settings

Theme

Ask HN: Creating html – templates vs. code

8 points by basiliothecat 11 years ago · 4 comments · 1 min read


With react and the likes creating markup in code, i wonder if people find templating solutions (in general) having some limitations or otherwise being inferior? Or it's just me being too attached to templates and seeing doing via code somewhat of a step backwards.

reverius42 11 years ago

A year ago, I would have agreed (that templating is cleaner, better separation, and going back to generating HTML from code would be a step backwards). Since I have been using React.js, my opinion has changed 100% -- and I realized that the supposed "separation of concerns" that drove us to template languages in the first place was an arbitrary separation. Separating components (a button, a form, a site header, what have you) is the kind of separation you want, not separating languages arbitrarily. If you look at the evolution of template languages, they sometimes start simple, but all of them have added sufficient logic to approach or surpass turing-completeness -- it turns out that you want to write templates with logic in them, that that is actually how you separate concerns effectively. The logic and rendered markup for a particular component should be cohesive; components should be loosely coupled together.

  • basiliothecatOP 11 years ago

    I pretty much agree with the reasoning how templating doesn't promote anything other than separation of languages. It always frowned how people emphasised templates being logic-less, which imo oversimplifies the matter.

    Yet i still don't seem comfortable writing the markup in js. Even react's JSX preprocessor doesn't seem right to me.

MalcolmDiggs 11 years ago

I love templating, particularly handlebars. If I'm working solo on a project it doesn't really matter...But if I'm partnering with a designer who only knows html + css, then the templates are a great way for them to contribute without a steep learning curve.

IMHO the best blend of templating and 2-way-binding (and other fanciness) is probably ember.js.

snikeris 11 years ago

My favorite library for this:

https://github.com/cgrand/enlive

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection