2016-07-01 87 views
0

嗨夥伴Liferay'ers,Liferay 7 Freemarker模板 - 獲取文章分類

我試圖用Freemarker模板得到一個journalArticle的類別。

我試過這段代碼:

<#assign journalArticleId = .vars['reserved-article-id'].data> 
<#assign journalArticleResourceLocalServiceUtil = staticUtil["com.liferay.portlet.journal.service.JournalArticleResourceLocalServiceUtil"]> 
<#assign assetCategoryLocalServiceUtil = staticUtil["com.liferay.portlet.asset.service.AssetCategoryLocalServiceUtil"]> 

<#assign articleResourcePK = journalArticleResourceLocalServiceUtil.getArticleResourcePrimKey(groupId, journalArticleId)/> 
<#assign categoryList=assetCategoryLocalServiceUtil.getCategories("com.liferay.portlet.journal.model.JournalArticle",articleResourcePK) > 

<#list categoryList as categoryList> 
${categoryList.getName()} 
</#list> 

當我執行的代碼,它拋出這個錯誤:

08:26:30,582 ERROR [http-nio-8080-exec-10][runtime:60] Error executing FreeMarker template 
FreeMarker template error: 
The following has evaluated to null or missing: 
==> staticUtil [in template "20202#20246#41671" at line 14, column 51] 

---- 
Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? 
---- 

---- 
FTL stack trace ("~" means nesting-related): 
     - Failed at: #assign journalArticleResourceLocalSe... [in template "20202#20246#41671" at line 14, column 1] 
---- 

Java stack trace (for programmers): 
---- 

有沒有人有一個想法是什麼,我做錯了什麼? 預先感謝您。

+0

在[THIS]中回答的問題(http://stackoverflow.com/questions/38241049/liferay-7-freemarker-template-staticutil-has-evaluated-to-null-o r-missing-tri/38302812?noredirect = 1#comment64023270_38302812)Post – balex

回答

0

我錯了我測試這個withi的Liferay 6.2

I tried your code that it's working for me make sure you have abilitate the services for template in portal-ext.properties

freemarker.engine.restricted.classes= 
freemarker.engine.restricted.variables= 
freemarker.engine.restricted.packages= 

在Liferay中7他們有改變的freemarker引擎的設置現在configurazion是在控制面板

Control Panel -> Configuration -> System Settings 
-> Foundation -> FreeMarker Engine -> Restricted Variables 

你必須刪除這裏的限制變量在這種情況下staticUtil

+0

感謝您的回覆,我添加了這行代碼,但它仍然無效。與以前一樣的錯誤。 – balex

+0

在這個Liferay你試過的代碼? – balex