Mustache templates: How to output a block only once for non-empty lists

前端 未结 3 827
傲寒
傲寒 2020-12-18 21:16

If my list is empty, I want to output this:

If my list i

3条回答
  •  情歌与酒
    2020-12-18 22:00

    If you don't want to or can't reformat your data or templating engine, you can also just check items.length before rendering the

      tags. Some people frown upon this, but it's definitely an alternative to Max's answer.

      {{#items.length}}
          
        {{items}}
      • {{name}}
      • {{/items}}
      {{/items.length}}

提交回复
热议问题