TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Creating html – templates vs. code

8 点作者 basiliothecat超过 10 年前
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.

3 条评论

reverius42超过 10 年前
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.
评论 #8793103 未加载
MalcolmDiggs超过 10 年前
I love templating, particularly handlebars. If I&#x27;m working solo on a project it doesn&#x27;t really matter...But if I&#x27;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.<p>IMHO the best blend of templating and 2-way-binding (and other fanciness) is probably ember.js.
snikeris超过 10 年前
My favorite library for this:<p><a href="https://github.com/cgrand/enlive" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;cgrand&#x2F;enlive</a>