Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Joost Verrijt
Display JournalArticle content in velocity template.
February 3, 2010 8:30 AM
Answer

Joost Verrijt

Rank: New Member

Posts: 7

Join Date: February 3, 2010

Recent Posts

I am trying to display some news items in a WebContent velocity template. For this I have created a service which delivers the desired news items. When I iterate over these items only the title is shown.

 1
 2#set ($extVelocityToolUtil = $utilLocator.findUtil('com.ext.portal.util.ExtVelocityToolUtil'))
 3#set ($news = $extVelocityToolUtil.getLatestNews($companyId, $groupId, "nieuws", 3))
 4
 5#foreach($news_item in $news)
 6    <div>
 7        News title:
 8        $news_item.getTitle()
 9    </div>
10    <div>
11        News content:
12        $news_item.getContent()
13    </div>       
14#end


I have also tried to use the $journalContentUtil.getContent() method to get the content for an article with a given id but to no avail. I am using Liferay 5.2.3.
Joost Verrijt
RE: Display JournalArticle content in velocity template.
February 16, 2010 5:06 AM
Answer

Joost Verrijt

Rank: New Member

Posts: 7

Join Date: February 3, 2010

Recent Posts

I found out you can do some nice things with the $saxReaderUtil to get the data from your defined structure elements.

So:

 1
 2#set ($extVelocityToolUtil = $utilLocator.findUtil('com.ext.portal.util.ExtVelocityToolUtil'))
 3#set ($news = $extVelocityToolUtil.getLatestNews($companyId, $groupId, "nieuws", 3))
 4
 5#foreach($news_item in $news)
 6    <div>
 7        News title:
 8        $news_item.getTitle()
 9    </div>
10    <div>
11        News content:
12        #set ($doc = $saxReaderUtil.read($news_item.getContentByLocale($request.locale)))
13        #set ($root = $doc.getRootElement())
14        #set ($content = $root.selectSingleNode("dynamic-element[@name='news_content']/dynamic-content").getText())
15        $content
16    </div>      
17#end
Joost Verrijt
RE: Display JournalArticle content in velocity template.
April 19, 2010 2:09 AM
Answer

Joost Verrijt

Rank: New Member

Posts: 7

Join Date: February 3, 2010

Recent Posts

We recently migrated to Liferay EE 5.2.7 and this approach no longer seems to work. getContentByLocale() does return the content structure but it does not contain any values. Is there another way to retrieve the values of the structure attributes?
scorgle .
RE: Display JournalArticle content in velocity template.
August 16, 2010 5:12 AM
Answer

scorgle .

Rank: New Member

Posts: 1

Join Date: February 24, 2010

Recent Posts

getContentByLocale() didn't work for me either in Liferay 5.2.3, but the following workaround (which only uses the url of a web content) did:

 1## initialize article service
 2#set ($journalArticleLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService"))
 3
 4## get article id for a web content named "footer" (actually the function uses the url generated from the name)
 5#set ($articleId = $journalArticleLocalService.getArticleByUrlTitle($themeDisplay.getScopeGroupId(), "footer").getArticleId())
 6
 7## get content for article id
 8#set ($articleContent = $journalContentUtil.getContent($themeDisplay.getScopeGroupId(), $articleId, null, $locale.toString(), $themeDisplay))
 9
10## display article content
11$articleContent
chirag @ India
RE: Display JournalArticle content in velocity template.
March 22, 2013 2:41 AM
Answer

chirag @ India

Rank: Regular Member

Posts: 129

Join Date: December 20, 2011

Recent Posts

this coding is not workng in liferay 6.1.x version

I have the code which is working in liferay 6.0 version
please any body help me to solve this problem

#set ($journalArticleLocalService = $serviceLocator.findService('com.liferay.portlet.journal.service.JournalArticleLocalService'))
#set ($localeTransformer = $portal.getClass().forName('com.liferay.portlet.journal.util.LocaleTransformerListener').newInstance())
#set ($VOID = $localeTransformer.setLanguageId($request.theme-display.language-id))
#set ($companyId = $getterUtil.getLong($request.theme-display.company-id))
#set ($scopeGroupId = $getterUtil.getLong($request.theme-display.scope-group-id))
#set ($obc = $portal.getClass().forName("com.liferay.portlet.journal.util.comparator.ArticleDisplayDateComparator").newInstance())
#set ($articles = $journalArticleLocalService.search($companyId, $scopeGroupId, '', null, null, null, null, null, null, 0, null, -1, -1, $obc))
<ul>
#foreach ($article in $articles)
#set ($xml = $localeTransformer.onXml($article.content))
#set ($doc = $saxReaderUtil.read($xml))
#set ($title = $doc.valueOf("//dynamic-element[@name='tittle']/dynamic-content/text()"))
${title}
#end
</ul>
Kevin Wang
RE: Display JournalArticle content in velocity template.
April 29, 2014 8:11 AM
Answer

Kevin Wang

Rank: New Member

Posts: 7

Join Date: September 3, 2013

Recent Posts

this coding is workng in liferay 6.1.0 version

#set ($journalArticleLocalService = $serviceLocator.findService('com.liferay.portlet.journal.service.JournalArticleLocalService'))
#set ($languageId = $request.theme-display.language-id)
#set ($companyId = $getterUtil.getLong($request.theme-display.company-id))
#set ($scopeGroupId = $getterUtil.getLong($request.theme-display.scope-group-id))

#set ($obc = $portal.getClass().forName("com.liferay.portlet.journal.util.comparator.ArticleDisplayDateComparator").newInstance())
#set ($list = $portal.getClass().forName("java.util.ArrayList").newInstance())

#set ($articles = $journalArticleLocalService.search($companyId, $scopeGroupId, 0, null, null, "news", "", "", null, null, 0, null, 0, 4, $obc))
<h1>$headerRight.getData()<h1>

<ul>
#foreach ($article in $articles)
#set ($articleUrl = "/web/guest/news/-/journal_content/" + $targetPortletID + "/" + $article.groupId + "/" + $article.articleId)
<h3>$article.getTitle($languageId)</h3>
<span>$article.userName</span>
<a href="${articleUrl}">Read More...</a>
#end
</ul>