Foros de discusión

RE: Velocity template - How to get distinct fields from journal articles

Michael Reiche, modificado hace 14 años.

Velocity template - How to get distinct fields from journal articles

New Member Mensajes: 22 Fecha de incorporación: 14/01/07 Mensajes recientes
I have some articles which have their own structure. These I would like to be aggregated into one article. I've been trying to use (another) article based on a velocity macro like this:

<h1>$reserved-article-title.data - company: $companyId</h1>
#set ($journalLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService"))
#set ($obc = $portal.getClass().forName("com.liferay.portlet.journal.util.comparator.ArticleCreateDateComparator").newInstance())
#set ($articles = $journalLocalService.search($getterUtil.getLong($companyId),-1,"",null,"test","RELEASENOTE","RELEASENOTE",null,null,true,false,null,0,9999,$obc))

#foreach ($article in $articles)
<div><h2>Article $article.articleId - $article.groupId - $article.title</h2><br>
$article.getAvailableLocales().toString()<br>
$article.getContent()
</div>
<br>
#end

That works perfectly. However I'm not interested in $article.getContent() - I would rather like to get access of my own individual fields of $article - Is it possible, and how do I accomplish that?

Greetings/Michael
thumbnail
Bruno Farache, modificado hace 14 años.

RE: Velocity template - How to get distinct fields from journal articles

Liferay Master Mensajes: 603 Fecha de incorporación: 14/05/07 Mensajes recientes
Michael, I blogged about some web content enhancements here, you can download the sample code here, look in the templates folder for examples.

If you are using the search method that returns Hits you can simply do $article.fieldName, if you have used some search method that returns List<JournalArticle> you can use $saxReaderUtil to iterate over the article xml.
Michael Reiche, modificado hace 14 años.

RE: Velocity template - How to get distinct fields from journal articles

New Member Mensajes: 22 Fecha de incorporación: 14/01/07 Mensajes recientes
Thanks,

I've been around the Blog, and several other places :-) And also got it to work by using the saxReaderUtil to fetch out my individual fields from the JournalArticle.

But! as this specific task requires some other logic involving custom attributes on user and organization, I found my expertise into velocity a bit on the low end. It is just to time consuming to digg up which fields are available through Velocity in the given context. I ended up adding a custom portlet for this task.



/Michael
thumbnail
Stephen Skinner, modificado hace 14 años.

RE: Velocity template - How to get distinct fields from journal articles

Junior Member Mensajes: 28 Fecha de incorporación: 29/01/10 Mensajes recientes
Hello, I followed those links and just can't seem to get this going. Feeling mighty dense. Here is what mostly works...

#set ($journalLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil"))
#set ($documents = $journalLocalService.getStructureArticles($getterUtil.getLong($groupId), "POLICY"))
#foreach ($document in $documents)
   $document.title<br>    ## good
   $document.myfield<br>  ## no good
#end

title is the 'reserved' field and seems to be easily accessible (also articleId and others presumably). Problem is I cannot retrieve my 'custom' fields in the structure (this thread). Tried a great number of permutations and saxReaderUtil lines of code but no good. Any chance someone can help me with the code/syntax I need?
thumbnail
Stephen Skinner, modificado hace 13 años.

RE: Velocity template - How to get distinct fields from journal articles

Junior Member Mensajes: 28 Fecha de incorporación: 29/01/10 Mensajes recientes
Ok - got the saxReaderUtil version to work - was trying to blend the two but now get its one (service calls) or the other (sax). This forum post helped as well: LINK "Get the last article in velocity"

I'm unstuck, but if someone knows the way to get the custom fields with the service call version, I'm sure that would be helpful.