如何使用freemarker循环显示图像?

时间:2012-02-22 03:45:10

标签: arrays loops freemarker

我正在编写一个自动标记模板,自动按如下方式显示星级,但是我无法根据计算的星级评分循环显示“星星”图像:

[#assign starRatingsRaw = "${product.landRating}"]
[#assign numOnly = starRatingsRaw?replace(" Star","")]
[#assign numOnly = numOnly?number]
[#assign starCnt = numOnly?int]
${starCnt}

[#list ["<img src="/img/global/graphics/star.gif"/>"] as x]
     ${x}
[/#list]

1 个答案:

答案 0 :(得分:0)

[#if starCnt > 0]
   [#list 1..starCnt as level]
      <img src="/img/global/graphics/star.gif"/>
   [/#list]
[/#if]

或更常见的是灰色尾随星:

[#list 1..5 as level]
    <img src="/img/global/graphics/star[#if starCnt > level]-gray[#if].gif"/>
[/#list]