2017-06-26 183 views
1

我正在使用Liferay 7.0 ga3,并且想要使用web内容的结构/模板(freemarker)制作轮播(bootstarp)。 该结构允许在我的传送带中显示多个Web内容。但在我的模板cur_WebContent.getData()显示的className和的WebContent的ID: “remove_ending”将Web内容显示到Web内容模板中

{"className":"com.liferay.journal.model.JournalArticle","classPK":"42553"} 

于是我就用 “?keep_after”,并获得只有我的ID:

<#assign journalArticleLocalService = serviceLocator.findService("com.liferay.journal.service.JournalArticleLocalService")> 

<#assign web_content_id= cur_WebContent.getData()?keep_after("classPK\":\"")?remove_ending("\"}") > 

<#assign cur_articleID = journalArticleLocalService.fetchArticle(groupId, web_content_id)> 
${journalArticleLocalService.getArticleContent(cur_articleID, cur_articleID.getDDMTemplateKey(), "VIEW", locale, themeDisplay)} 

我可以显示在我的旋转木马一样$ {} web_content_id此信息,但如果我在fetchArticle使用这个(的groupId条款ArticleID),这是行不通的:

FreeMarker template error: 
The following has evaluated to null or missing: 
==> journalArticleLocalService.fetchArticle(groupId, web_content_id) [in template "20116#20160#47034" at line 7, column 30] 

---- 
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 cur_articleID = journalArticl... [in template "20116#20160#47034" at line 7, column 5] 
---- 

有什么想法? 感谢

+0

classPK是不同的ID的web内容的... –

回答

1

我想web_content_id需要被转化为一个数

<#assign web_content_id = [...]?number /> 
+0

它不能是一个数字。字符串是必需的 –

1

这里classPK = “42553”,但classPK是ID的网页内容的不同。

Astuce:ID = classPK -2 < => ID = 42553 - 2 = 42551