开发者

Freemarker assign list length to local variable

开发者 https://www.devze.com 2023-01-18 15:59 出处:网络
The following freemarker code causes an exception <#assign开发者_开发知识库 i= it.getList().size()>

The following freemarker code causes an exception

<#assign开发者_开发知识库 i= it.getList().size()>
<#list it.getList() as elem>
    <#if i==1>
    <li>${elem.name}</li>
    <#else>
    <li class="marked">${elem.name}</li>
    </#if>
    <#assign i = i-1>
</#list>

The following exception is thrown:

Expected hash. it.getList() evaluated instead to freemarker.template.SimpleSequence

Anyone knows why? How can i assign the length of the list to my variable i?


I figured out, that it did not understood the syntax for the size built-in. The right syntax for assigning the size of a list to a local variable is

<#assign i = it.getList()?size>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号