$reserved-article-url-title.data doesn't provide i18n friendly URL

Issue

  • If you have a content with different friendly URLs per language, when trying to retrieve those friendly URL via velocity template, $reserved-article-url-title.data doesn't provide internationalized URL.
  • Per example, you have a web content with below URLs for Spanish (ES) and English (EN):
    • friendly URL ES: http://localhost:8080/es/web/test-page/-/testcontentes
    • friendly URL EN: http://localhost:8080/en/web/test-page/-/testcontenten
  • If you create a Web Content Template with $reserved-article-url-title.data to retrieve URL, it doesn't show a different URL per locale: a URL for the default locale is shown.

Environment

  • Liferay DXP 7.2

Resolution

  • In order to show a different URL per locale in a web content template, you have to obtain the friendly-URL based on its FriendlyUrlEntryLocalization.
  • Below is an example that could be used for velocity templates:
    #set ($longGroupId = $getterUtil.getLong($groupId))
    #set ($journalArticleResourceService = $serviceLocator.findService("com.liferay.journal.service.JournalArticleResourceLocalService"))

    #set($articleResource = $journalArticleResourceService.fetchArticleResource($longGroupId,$reserved-article-id.data))
    #set ($articleResourcePK = $articleResource.getResourcePrimKey())

    #set ($classNameLocalService = $serviceLocator.findService("com.liferay.portal.kernel.service.ClassNameLocalService"))
    #set ($friendlyUrlEntryService = $serviceLocator.findService("com.liferay.friendly.url.service.FriendlyURLEntryLocalService"))
    #set ($classnameId = $classNameLocalService.getClassNameId("com.liferay.journal.model.JournalArticle"))


    #set($entries = $friendlyUrlEntryService.getFriendlyURLEntries($longGroupId,$getterUtil.getLong($classnameId),$getterUtil.getLong($articleResourcePK)))

    #set($url-title = "")
    #foreach( $entry in $entries )
        #set($entryLocalization = $friendlyUrlEntryService.getFriendlyURLEntryLocalization($entry.friendlyURLEntryId,$locale.toString()))
        #set($url-title = $entryLocalization.urlTitle)
    #end

    $url-title
这篇文章有帮助吗?
0 人中有 0 人觉得有帮助