Freemarker assign list length to local variable

大憨熊 提交于 2019-12-03 06:55:33

问题


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?


回答1:


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>


来源:https://stackoverflow.com/questions/3864022/freemarker-assign-list-length-to-local-variable

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