Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The Handlebars template engine works the way you're talking about. The "each" helper loops through an array. You can put in an "else" block for when the array is empty.

  {{#each paragraphs}}
      <p>{{this}}</p>
  {{else}}
      <p class="empty">No content</p>
  {{/each}}
--- https://handlebarsjs.com/builtin_helpers.html


Django templates also have such a clause but it is named "empty" instead of "else".


I like this ternary approach.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: