Vista combinada Visión Plana Vista de árbol
Discusiones [ Anterior | Siguiente ]
toggle
Michael Reiche
Velocity template - How to get distinct fields from journal articles
29 de noviembre de 2009 14:05
Respuesta

Michael Reiche

Ranking: New Member

Mensajes: 22

Fecha de incorporación: 14 de enero de 2007

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
Bruno Farache
RE: Velocity template - How to get distinct fields from journal articles
29 de noviembre de 2009 14:26
Respuesta

Bruno Farache

LIFERAY STAFF

Ranking: Liferay Master

Mensajes: 532

Fecha de incorporación: 14 de mayo de 2007

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
RE: Velocity template - How to get distinct fields from journal articles
4 de diciembre de 2009 0:09
Respuesta

Michael Reiche

Ranking: New Member

Mensajes: 22

Fecha de incorporación: 14 de enero de 2007

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
s s
RE: Velocity template - How to get distinct fields from journal articles
22 de abril de 2010 9:34
Respuesta

s s

Ranking: New Member

Mensajes: 24

Fecha de incorporación: 29 de enero de 2010

Mensajes recientes

Hello, I followed those links and just can't seem to get this going. Feeling mighty dense. Here is what mostly works...
1
2#set ($journalLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil"))
3#set ($documents = $journalLocalService.getStructureArticles($getterUtil.getLong($groupId), "POLICY"))
4#foreach ($document in $documents)
5   $document.title<br>    ## good
6   $document.myfield<br>  ## no good
7#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?
s s
RE: Velocity template - How to get distinct fields from journal articles
23 de abril de 2010 5:07
Respuesta

s s

Ranking: New Member

Mensajes: 24

Fecha de incorporación: 29 de enero de 2010

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.