troad 3 days ago

Phoenix (Elixir) has a very elegant version of that, without the need for the extra indent:

  <p :for={para <- paras} class={para.class} {para.attrs}>
    {para.text}
  </p>
With :for being a list comprehension.

1
notpushkin 3 days ago

I was afraid at first this is the only option (which makes it difficult to generalize this to loops with body consisting of anything but a single element). But as an optional shorthand it is indeed pretty neat! (Personally though, I still like explicit “layering” of a separate `for` block a bit more.)

troad 9 hours ago

Interesting! I actually find the in-lined forms far more explicit. For me, the use of `<%=` blocks tends to muddle the structure of the underlying HTML, so I avoid them where possible (not always the case though, as you rightly note).