掲示板

Freemark in Web Content Template

thumbnail
8年前 に Sebastian Wörner によって更新されました。

Freemark in Web Content Template

Junior Member 投稿: 46 参加年月日: 14/11/18 最新の投稿
Hi,

i tried to code my own Template for Web Content with freemark.

Its easy to get the fields of the Structure (e.g. ${title.getData()}
But i found no way to get the 'metadata' from the web content, e.g. the create date, the author, the tags and the categories.

In coding a display template with freemark for the asset publisher you iterate over all entries and the entry objects give you access to this metadata.
So, i think, there must be an object to get the metadata in Web Content Template too, or?

Thanks for helping me
thumbnail
8年前 に Miroslav Ligas によって更新されました。

RE: Freemark in Web Content Template

Regular Member 投稿: 152 参加年月日: 14/07/29 最新の投稿
Yes there are ways how to get to the data. James F. posted a nice script that shows you what data are stored in the context. Just copy&paste the script in a template.

https://gist.githubusercontent.com/jamesfalkner/8832377/raw/55b4ffd989e4f1b552ae6f8d98251b3e7bafb9c1/liferay_dump.ftl

You'll then see that there are thing like reserved-article-create-date, reserved-article-author-name...
thumbnail
8年前 に Sebastian Wörner によって更新されました。

RE: Freemark in Web Content Template

Junior Member 投稿: 46 参加年月日: 14/11/18 最新の投稿
Thanks for sharing this script.
It helps emoticon

But i have still two missing meta data
1) expire date
i can get Create Date (${.data_model['reserved-article-create-date'].data}) or Display Date (${.data_model['reserved-article-display-date'].data})
But no way to get the expire date?!

2) Categories
I can access the tag names with ${.data_model['reserved-article-asset-tag-names'].data}
But no way to get the Categories?!

Has anybody a hint for this?
thumbnail
8年前 に Sebastian Wörner によって更新されました。

RE: Freemark in Web Content Template

Junior Member 投稿: 46 参加年月日: 14/11/18 最新の投稿
Nobody here, who can help me, to get the two properties?

1) expire date
i can get Create Date (${.data_model['reserved-article-create-date'].data}) or Display Date (${.data_model['reserved-article-display-date'].data})
But no way to get the expire date?!

2) Categories
I can access the tag names with ${.data_model['reserved-article-asset-tag-names'].data}
But no way to get the Categories?!

Thanks
thumbnail
8年前 に Zsolt - Jácint Balogh によって更新されました。

RE: Freemark in Web Content Template

Junior Member 投稿: 91 参加年月日: 13/10/09 最新の投稿
Hi,

You can use the liferay services in VM template if you enable them in the portal-ext.properties.
Here you can find a template witch is getting the article categories:

#set ($groupId = $themeDisplay.getLayout().getGroupId())
#set ($journalArticleLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService"))
#set ($ja = $journalArticleLocalService.getArticle( $groupId, $reserved-article-id.data ))
#set ($resourceprimKey = $ja.getResourcePrimKey())
#set ($assetEntryLocalService = $serviceLocator.findService("com.liferay.portlet.asset.service.AssetEntryLocalService"))
#set ($assetEntry = $assetEntryLocalService.getEntry("com.liferay.portlet.journal.model.JournalArticle", $resourceprimKey))
#set ($categoryUtil = $serviceLocator.findService("com.liferay.portlet.asset.service.AssetCategoryLocalService"))
#set ($categoryPorpertyService = $serviceLocator.findService("com.liferay.portlet.asset.service.AssetCategoryPropertyLocalService"))
#set ($assetCategories = $categoryUtil.getAssetEntryAssetCategories($assetEntry.getEntryId()))
#set ($category = $assetCategories.get(0))
#set ($categoryColor = $categoryPorpertyService.getCategoryProperty($category.getCategoryId(),"color"))

#set ($newDate = $dateTool.toDate("EEE, dd MMM yyyy hh:mm:ss Z", $reserved-article-display-date.getData(), $locale))
#set ($formattedDate = $dateTool.format("yyyy. MMMMM dd.", $newDate, $locale))

##The deafult display style is for the article detail page. 
<div class="detail-page-article-content-wrapper"> 	
	<h2 style="color:#$categoryColor.getValue()">
		$!reserved-article-title.data
	</h2>
	<p class="date-publish">$formattedDate</p>
	<div class="detail-page-artcile-content">
		$!Hir_Leiras.getData()
	</div>
	
</div>


from the $assetEntry object you can get the expiration date too.

Regards,
Zsolt
thumbnail
8年前 に Vishal Kumar によって更新されました。

RE: Freemark in Web Content Template

Regular Member 投稿: 198 参加年月日: 12/12/12 最新の投稿
Yes, Zsolt is right. By the object you can get
thumbnail
8年前 に Sebastian Wörner によって更新されました。

RE: Freemark in Web Content Template

Junior Member 投稿: 46 参加年月日: 14/11/18 最新の投稿
When i try to use the serviceLocator:

&lt;#assign assetEntryLocalService = serviceLocator.findService("com.liferay.portlet.asset.service.AssetEntryLocalService")/&gt;


i get this error:
Expression serviceLocator is undefined on line 46, column 35 in 20154#20194#27051.

But the property "freemarker.engine.restricted.variables" is set:


Any Idea why?
Thanks

添付ファイル:

thumbnail
8年前 に Dominique Ebert によって更新されました。

RE: Freemark in Web Content Template (回答)

Junior Member 投稿: 29 参加年月日: 13/02/01 最新の投稿
In Liferay 6.2 there are two properties for each (velocity and freemarker) that manage the restrictions.
For freemarker those would be:

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

You set your variables to freemarker.engine.restricted.variables="" but your still restricting classes. Maybe you should try to change something there in order to get your ftl working.
thumbnail
8年前 に Miroslav Ligas によって更新されました。

RE: Freemark in Web Content Template (回答)

Regular Member 投稿: 152 参加年月日: 14/07/29 最新の投稿
This should disable all the restrictions

velocity.engine.restricted.classes=
velocity.engine.restricted.variables=
freemarker.engine.restricted.classes=
freemarker.engine.restricted.variables=
thumbnail
8年前 に Sebastian Wörner によって更新されました。

RE: Freemark in Web Content Template

Junior Member 投稿: 46 参加年月日: 14/11/18 最新の投稿
Yes, it works now.

The entries:
velocity.engine.restricted.classes=
velocity.engine.restricted.variables=
freemarker.engine.restricted.classes=
freemarker.engine.restricted.variables

are all empty now.
Now it works :-)