by notpushkin · 1y ago · 0 comments
<ul>
{% for user in users %}
<li>{{ user.firstName }}</li>
{% endfor %}
</ul>
And we have good syntax for templates now: <ul>
{#each users as user}
<li>{user.firstName}</li>
{/each}
</ul>
Why do we have to squish everything into HTML-like-but-not-quite blocks?But no, JSX isn’t that great either:
<ul>
{users.map(user => (
<li>{user.firstName}</li>
))}
</ul></each> is about control flow, so it's a conceptually different thing.
I can't tell how convincing that argument is to be honest, and how much I'm just rationalising familiarity.
Where they aren't two different things, you have some kind of component configuration language, like WPF on .NET. There is no control language, the instantiated components have behaviours and are responsible for any control logic, like rendering a list of items. This isn't a template language though.
HTML now has web components and so you can think of it in the latter way. I'm not sure if anyone has take this approach though.
SGML (XML, HTML) is for content (text) authors not developers, but webdevs just don't get it and look at it as a solution to developer problems.
I like vue a lot more;
<ul v-if={users}>
<li v-for={some in users}>{some.name}
</ul> <ul #if={users}>
{#each users as user}
<li>{user.name}</li>
{/each}
</ul>