我試圖從FreeMarker中的字符串中獲取子字符串。 但是有2個thigns考慮:限制FreeMarker中的字符串長度
- 字符串可以爲空
- 字符串可能是短於最大字符串長度
我做到以下幾點:
<#list landingpage1.popularItems as row>
<li>
<span class="minititle">
<#assign minititle=(row.title!"")>
<#if minititle?length < 27>
${minititle}
<#else>
${minititle?substring(0,26)} ...
<#/if>
</span>
</li>
</#list>
我收到一個freemarker錯誤說:
Failed to load templates: Encountered "</#list>" at line 144, column 65 in landingpage1.ftl.
Was expecting one of:
<ATTEMPT> ...
<IF> ...
<LIST> ...
<FOREACH> ...
<SWITCH> ...
<ASSIGN> ...
<GLOBALASSIGN> ...
<LOCALASSIGN> ...
<INCLUDE> ...
<IMPORT> ...
<FUNCTION> ...
<MACRO> ...
<TRANSFORM> ...
<VISIT> ...
<STOP> ...
<RETURN> ...
<CALL> ...
<SETTING> ...
<COMPRESS> ...
<COMMENT> ...
<TERSE_COMMENT> ...
<NOPARSE> ...
<END_IF> ...
<BREAK> ...
<SIMPLE_RETURN> ...
<HALT> ...
<FLUSH> ...
<TRIM> ...
<LTRIM> ...
<RTRIM> ...
<NOTRIM> ...
<SIMPLE_NESTED> ...
<NESTED> ...
<SIMPLE_RECURSE> ...
<RECURSE> ...
<FALLBACK> ...
<ESCAPE> ...
<NOESCAPE> ...
<UNIFIED_CALL> ...
<WHITESPACE> ...
<PRINTABLE_CHARS> ...
<FALSE_ALERT> ...
"${" ...
"#{" ...
很奇怪。 任何人都可以幫忙嗎?
你是對的!感謝2年後的跟進! – 2013-01-18 07:55:59
呵呵:)我發現你的帖子尋找一個「截斷」的答案,我只是碰巧注意到你的錯誤,它看起來就像我昨天所做的一樣(出於同樣的原因)。我也一個小時都在抨擊我的頭腦! – RockMeetHardplace 2013-01-18 13:44:18