Forums de discussion

RE: get the last article in velocity

thumbnail
Filippo Boatto, modifié il y a 14 années.

get the last article in velocity

Regular Member Publications: 107 Date d'inscription: 01/02/07 Publications récentes
i would get the last article of type "marketing" in a velocity template.
This is my code:

#set($journalArticleLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService"))

#set($keywords = "")
#set($version = "")
#set($type = "marketing")
#set($structureIds = "")
#set($templateIds = "")
#set($displayDateGT = "")
#set($displayDateLT = "")
#set($approved = "true")
#set($expired = "false")
#set($reviewDate = "")
#set($start = "")
#set($end = "")
#set($obc = "DESC")

#set($journalArticlesList = $journalArticleLocalService.search(
										 $companyId, $groupId, 
       									         $keywords, $type, 
	   									 $structureIds, $templateIds, 
	   									 $displayDateGT, $displayDateLT,
										 $approved, $expired, 
										 $reviewDate, 
										 $start, $end, $obc))

#foreach ($journalArticle in $journalArticlesList )
  $journalArticle.getTitle()<br>
#end


but doesn't works :-(
any suggestions?
thumbnail
Amos Fong, modifié il y a 14 années.

RE: get the last article in velocity

Liferay Legend Publications: 2047 Date d'inscription: 07/10/08 Publications récentes
You want to get the orderbycomparator like this:

#set ($obc = $portal.getClass().forName("com.liferay.portlet.journal.util.comparator.ArticleCreateDateComparator").newInstance()))


Also you want to use $getterUtil.getLong($groupId) and $getterUtil.getLong($companyId) too or it won't work. There might be some other syntax errors in your code because it didn't work for me.

Make sure you have method and types correct in passing to the method.
thumbnail
Filippo Boatto, modifié il y a 14 années.

RE: get the last article in velocity

Regular Member Publications: 107 Date d'inscription: 01/02/07 Publications récentes
thanks Amos Fong!!
now with thi code:

#set($journalArticleLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService"))

#set($company = $getterUtil.getLong($companyId))
#set($group = $getterUtil.getLong($groupId))
#set($keywords = "")
#set($version = $null.null)
#set($type = "products")
#set($structureId = "")
#set($templateId = "")
#set($displayDateGT = $getterUtil.getDate("19990101",$dateUtil.getISOFormat("19990101")))
#set($displayDateLT = $null.null)
#set($approved = $getterUtil.getBoolean("true"))
#set($expired = $getterUtil.getBoolean("false"))
#set($reviewDate = $null.null)
#set($start = -1)
#set($end = -1)
#set ($obc = $portal.getClass().forName("com.liferay.portlet.journal.util.comparator.ArticleDisplayDateComparator").newInstance())


#set($journalArticlesList = $journalArticleLocalService.search(
										 $company, $group,
       									         $keywords, $version,
       									         $type, $structureId, $templateId, 
	   									 $displayDateGT, $displayDateLT, $approved, 
	   									 $expired, $reviewDate,$start, $end, 
	   									 $obc))

#set($debug=$getterUtil.getBoolean("true"))
#if ($debug)
	@company_id@<br>
	@group_id@<br>
	portletgrp: $scopeGroupId<br>
	$company  <br>
	$group<br>
	
	$keywords<br>
	$version<br>
	$type<br>
	$structureIds<br>
	$templateIds<br>
	$displayDateGT<br>
	$displayDateLT<br>
	$approved<br>
	$expired<br>
	$reviewDate<br>
	$start<br>
	$end<br>
	$obc<br>
	
	journalListsize: $journalArticlesList.size()<br>
	
#end

#foreach ($article in $journalArticlesList )
  $article.***
#end


i have all articles that i need.
But the articles has a structure...
How to access the fields of the structure in the cycle "#foreach ($article in $journalArticlesList )" ?

for example my structure "article-news" has a field "article-big-image" and $article is created with this structure.
How could i access the propertie "article-big-image" of the $article?
thumbnail
Amos Fong, modifié il y a 14 années.

RE: get the last article in velocity

Liferay Legend Publications: 2047 Date d'inscription: 07/10/08 Publications récentes
thumbnail
Filippo Boatto, modifié il y a 14 années.

RE: get the last article in velocity

Regular Member Publications: 107 Date d'inscription: 01/02/07 Publications récentes
Solved using liferay 5.2.3 and velocity template

Structure:

<root>
  <dynamic-element name="titoloTesto" type="text" repeatable="false"></dynamic-element>
  <dynamic-element name="titoloLink" type="document_library" repeatable="false"></dynamic-element>
  <dynamic-element name="testoBreve" type="text_box" repeatable="false"></dynamic-element>
  <dynamic-element name="testoEsteso" type="text_area" repeatable="false"></dynamic-element>
  <dynamic-element name="immaginePiccola" type="image" repeatable="false"></dynamic-element>
  <dynamic-element name="immagineDettaglio1" type="image" repeatable="false"></dynamic-element>
  <dynamic-element name="testoImmagineDettaglio1" type="text" repeatable="false"></dynamic-element>
  <dynamic-element name="immagineDettaglio2" type="image" repeatable="false"></dynamic-element>
  <dynamic-element name="testoImmagineDettaglio2" type="text" repeatable="false"></dynamic-element>
  <dynamic-element name="immagineDettaglio3" type="image" repeatable="false"></dynamic-element>
  <dynamic-element name="testoImmagineDettaglio3" type="text" repeatable="false"></dynamic-element>
  <dynamic-element name="attachment1" type="document_library" repeatable="false"></dynamic-element>
  <dynamic-element name="descrizioneAttachment1" type="text" repeatable="false"></dynamic-element>
  <dynamic-element name="attachment2" type="document_library" repeatable="false"></dynamic-element>
  <dynamic-element name="descrizioneAttachment2" type="text" repeatable="false"></dynamic-element>
  <dynamic-element name="attachment3" type="document_library" repeatable="false"></dynamic-element>
  <dynamic-element name="descrizioneAttachment3" type="text" repeatable="false"></dynamic-element>
  <dynamic-element name="attachment4" type="document_library" repeatable="false"></dynamic-element>
  <dynamic-element name="descrizioneAttachment4" type="text" repeatable="false"></dynamic-element>
  <dynamic-element name="attachment5" type="document_library" repeatable="false"></dynamic-element>
  <dynamic-element name="descrizioneAttachment5" type="text" repeatable="false"></dynamic-element>
  <dynamic-element name="attachment6" type="document_library" repeatable="false"></dynamic-element>
  <dynamic-element name="descrizioneAttachment6" type="text" repeatable="false"></dynamic-element>
</root>


Template (to show the last news of type "marketing"):

<!-- Questo template estrae l'ultima news di tipo marketing 
     e visualizza i campi della propria struttura 
-->

#set ($document = $saxReaderUtil.readURL("http://@portal_url@/c/journal/get_articles?groupId=@group_id@&amp;type=[b]marketing[/b]&amp;delta=[b]1[/b]&amp;approved=true&amp;expired=false&amp;orderBy=display-date"))
#set ($root = $document.getRootElement())
#set ($articles = $root.selectNodes("/result-set/result/root"))

#foreach ($article IN $articles)
  #set ($articleId = $article.selectSingleNode("dynamic-element[@name='reserved-article-id']/dynamic-content"))
  #set ($articleTitle = $article.selectSingleNode("dynamic-element[@name='reserved-article-title']/dynamic-content"))
  #set ($articleModifiedDate = $article.selectSingleNode("dynamic-element[@name='reserved-article-modified-date']/dynamic-content"))
  #set ($articleAuthorName = $article.selectSingleNode("dynamic-element[@name='reserved-article-author-name']/dynamic-content"))

  <!-- recupero i dati della struttura -->
  #set ($article_TitoloLink= $article.selectSingleNode("dynamic-element[@name='titoloLink']/dynamic-content"))
  #set ($article_TitoloTesto = $article.selectSingleNode("dynamic-element[@name='titoloTesto']/dynamic-content"))
  #set ($article_ImmaginePiccola = $article.selectSingleNode("dynamic-element[@name='immaginePiccola']/dynamic-content"))
  #set ($article_TestoBreve = $article.selectSingleNode("dynamic-element[@name='testoBreve']/dynamic-content"))

<div id="news_sx">
   <div class="testo">
       <p>
       <!-- titolo della news attiva-->
       	  #if ($article_TitoloLink.getData()!="")  
       	     #set ($articleUrl = "$article_TitoloLink.getData()")
             #set ($target = "_blank")
       	  #else
             #set ($articleUrl = "http://@portal_url@/web/4ws-trade/news-detail/-/journal_content/56_INSTANCE_8Rjo/@group_id@/$articleId.getData()")
            #set ($target = "_top")
       	  #end
       	  </p><h2 class="titolo_news"><a href="$articleUrl" target="$target">$article_TitoloTesto.getData()</a></h2>
          <!-- testo della news attiva-->
          #if ($article_ImmaginePiccola.getData()!="")
          	<h4 style="width:292px">
          		$article_TestoBreve.getData()
          	</h4>
          #else
          	<h4 style="width:400px">
          		$article_TestoBreve.getData()
          	</h4>
          #end
       <p></p>
   </div>
   #if ($article_ImmaginePiccola.getData()!="")
      <div class="immagine">
         <a href="$articleUrl" target="$target"><img src="$article_ImmaginePiccola.getData()" style="max-width: 120px;	max-height: 120px;" border="0"></a>
      </div>
   #end
</div>
#end
thumbnail
Amos Fong, modifié il y a 14 années.

RE: get the last article in velocity

Liferay Legend Publications: 2047 Date d'inscription: 07/10/08 Publications récentes
wow nice work Filippo!
thumbnail
willard largueza macay, modifié il y a 13 années.

RE: get the last article in velocity

New Member Publications: 9 Date d'inscription: 14/01/10 Publications récentes
wow.. this is what i need.. i will try this.. emoticon
thumbnail
GALLET Victor, modifié il y a 12 années.

RE: get the last article in velocity

New Member Publications: 12 Date d'inscription: 09/03/11 Publications récentes
Very nice job Filippo. I thank you emoticon
Eduardo Grotteschi, modifié il y a 10 années.

RE: get the last article in velocity

New Member Publications: 22 Date d'inscription: 12/11/13 Publications récentes
Hi guys, i am having troubles trying to build my asset template using velocity.

I added the portal-ext.properties file to remove the blockers:

velocity.engine.restricted.classes=
velocity.engine.restricted.variables=
freemarker.engine.restricted.classes=
freemarker.engine.restricted.variables=


And then i tried to add this code to my template:

#set ($document = $saxReaderUtil.readURL("http://localhost:8080/c/journal/get_articles?delta=100&approved=true&expired=false&orderBy=display-date"))
#set ($root = $document.getRootElement())
#set ($articles = $root.selectNodes("/result-set/result/root"))

#foreach ($article IN $articles)
#set ($articleId = $article.selectSingleNode("dynamic-element[@name='Course_Title']/dynamic-content"))
Articulo = $articleId
#end

But nothing was printed on my template. This is the structure that i get when i call that url:

<result-set>
<result>
<root available-locales="en_US" default-locale="en_US">
<dynamic-element name="Course_Title" index="0" type="text" index-type="keyword">...</dynamic-element>
<dynamic-element name="Course_Description" index="0" type="text_box" index-type="keyword">...</dynamic-element>
<dynamic-element name="Free_Video_URL" index="0" type="text" index-type="keyword">...</dynamic-element>
<dynamic-element name="Upload_Date" index="0" index-type="keyword">...</dynamic-element>
...

The "Course_Title" is present in the resultset, but never access to the foreach.

Could you help me?
thumbnail
James Falkner, modifié il y a 10 années.

RE: get the last article in velocity

Liferay Legend Publications: 1399 Date d'inscription: 17/09/10 Publications récentes
Hey Eduardo, welcome to the community!

I believe you need to add a groupId parameter (since you are requesting all articles, but get_articles won't give you articles across all scopes) (and you should use the portal_url token as well). So can you try
#set ($document = $saxReaderUtil.readURL("http://@portal_url@/c/journal/get_articles?groupId=${scopeGroupId}&amp;delta=100&amp;approved=true&amp;expired=false&amp;orderBy=display-date"))
Eduardo Grotteschi, modifié il y a 10 années.

RE: get the last article in velocity

New Member Publications: 22 Date d'inscription: 12/11/13 Publications récentes
Thanks James!! now i can retrieve info for my articles!
Eduardo Grotteschi, modifié il y a 10 années.

RE: get the last article in velocity

New Member Publications: 22 Date d'inscription: 12/11/13 Publications récentes
James, i need something but couldnt find how to do it, i need to order the articles "descending" by article title, i tried this:

http://localhost:8080/c/journal/get_articles?groupId=${scopeGroupId}&type=Autor&delta=100&approved=true&expired=false&orderBy=article-title&desc

but nothing happend, do you know how to do it?

Regards.