Fórum

Freemark in Web Content Template

thumbnail
Sebastian Wörner, modificado 8 Anos atrás.

Freemark in Web Content Template

Junior Member Postagens: 46 Data de Entrada: 18/11/14 Postagens Recentes
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
Miroslav Ligas, modificado 8 Anos atrás.

RE: Freemark in Web Content Template

Regular Member Postagens: 152 Data de Entrada: 29/07/14 Postagens Recentes
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
Sebastian Wörner, modificado 8 Anos atrás.

RE: Freemark in Web Content Template

Junior Member Postagens: 46 Data de Entrada: 18/11/14 Postagens Recentes
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
Sebastian Wörner, modificado 8 Anos atrás.

RE: Freemark in Web Content Template

Junior Member Postagens: 46 Data de Entrada: 18/11/14 Postagens Recentes
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
Zsolt - Jácint Balogh, modificado 8 Anos atrás.

RE: Freemark in Web Content Template

Junior Member Postagens: 91 Data de Entrada: 09/10/13 Postagens Recentes
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
Vishal Kumar, modificado 8 Anos atrás.

RE: Freemark in Web Content Template

Regular Member Postagens: 198 Data de Entrada: 12/12/12 Postagens Recentes
Yes, Zsolt is right. By the object you can get
thumbnail
Sebastian Wörner, modificado 8 Anos atrás.

RE: Freemark in Web Content Template

Junior Member Postagens: 46 Data de Entrada: 18/11/14 Postagens Recentes
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
Dominique Ebert, modificado 8 Anos atrás.

RE: Freemark in Web Content Template (Resposta)

Junior Member Postagens: 29 Data de Entrada: 01/02/13 Postagens Recentes
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
Miroslav Ligas, modificado 8 Anos atrás.

RE: Freemark in Web Content Template (Resposta)

Regular Member Postagens: 152 Data de Entrada: 29/07/14 Postagens Recentes
This should disable all the restrictions

velocity.engine.restricted.classes=
velocity.engine.restricted.variables=
freemarker.engine.restricted.classes=
freemarker.engine.restricted.variables=
thumbnail
Sebastian Wörner, modificado 8 Anos atrás.

RE: Freemark in Web Content Template

Junior Member Postagens: 46 Data de Entrada: 18/11/14 Postagens Recentes
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 :-)