Reputation: 1
I need to set some custom tag in portal_normal.vm which define in each Web Content.
My case:
<meta property="og:title" content="$themeDisplay.getScopeGroup().getExpandoBridge().getAttribute('custom_metas')" />
This code only works if custom field is created in site (not in web content). When I create in web content show as plain text.
In my portal-ext.properties put:
journal.template.velocity.restricted.variables=
Nothing change.
Finally I try this solution given in liferay forums but doesn't work. Notice: $reserved-article-id.data doesn't print nothing.
#set ($journalArticleLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService"))
#set ($ja = $journalArticleLocalService.getArticle($getterUtil.getLong($groupId),$getterUtil.getString($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($JournalArticleResourceLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleResourceLocalService"))
#set ($journalArticleResource = $JournalArticleResourceLocalService.getArticleResource($assetEntry.getClassPK()))
#set($JournalArticleLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService"))
#set ($journalArticle = $JournalArticleLocalService.getArticle($getterUtil.getLong($groupId), "$journalArticleResource.getArticleId()"))
#set ($custom = $journalArticle.getExpandoBridge().getAttribute("custom_metas"))
$custom display as plain text
Upvotes: 0
Views: 2103
Reputation: 9022
You are confusing theme templates with web content templates. In a theme template you have neither a single attached web content article, nor do you have access to any web content specific variable like $reserved-article-id
.
And you mix up pages and portlets. Your web content article is attached to a portlet on your page - and as you can have more than one portlet with a web content article on a page, you don't have the article that is loaded.
But if you attach a tag to your webcontent (not a custom field - just a tag in the Categorization section), that tag will be added to <meta name="keywords">
in the head automatically.
If you need the tags somewhere else - they are stored in the request attribute WebKeys.PAGE_KEYWORDS
(= "LIFERAY_SHARED_PAGE_KEYWORDS"
).
Upvotes: 1