0

I need to set some custom tag in portal_normal.vm which define in each Web Content.

My case:

  1. Go to Control Panel --> custom Field --> web content
  2. Create a new custom field called "custom_metas"
  3. Put this code in portal_normal.vm <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

Albertogf
  • 1
  • 1
  • 1
    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`. Do you want to show the tags of _all_ web content articles or of _one_ specific web content articles? – Tobias Liefke Sep 09 '15 at 20:01
  • I need to show the custom tag of the article that is loaded. My problem is that web content is loaded in body and I need to put in head tag. I read in liferay forums about custom fields but if it is posible to load web content in head – Albertogf Sep 09 '15 at 20:43

1 Answers1

1

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").

Tobias Liefke
  • 8,637
  • 2
  • 41
  • 58