Using dustjs how do I show a block of code when an array's size is greater than one

♀尐吖头ヾ 提交于 2019-12-24 06:44:47

问题


I am using dust 1.1.1. I've tried nesting the @size help inside of an @if but that broke.

Another trick to it is once I've determined the length is greater than one I then want to iterate through the array.


回答1:


The Dust grammar does not allow a helper to be used inside another helper, except in the body.

Instead, I would try something like this:

{#myArray}
  {@gt key=$len value=1}{.}{/gt}
{/myArray}

This will only output the value of the element in the array if the length of the array ($len) is greater than 1.




回答2:


My workaround for this was:

{?myArray[1]}
    {!Do greater than one stuff!}
{/myArray[1]}


来源:https://stackoverflow.com/questions/17220800/using-dustjs-how-do-i-show-a-block-of-code-when-an-arrays-size-is-greater-than

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!