Forums de discussion

Velocity - Template - Structure - LR6.2

Eduardo Grotteschi, modifié il y a 10 années.

Velocity - Template - Structure - LR6.2

New Member Publications: 22 Date d'inscription: 12/11/13 Publications récentes
GM! after 2 weeks of workaround i need your help because i coulndt find a solution.

I have 2 structures, with 2 templates, which i used to create my WebContent. Thats works fine, i am able to create the WC and populate the data, and show my personal layout with the templates. But, the problem begins when i want to use the Asset Publisher, because the Full and Abstract view are not usefull for me, so i tried to create a new template for the AP usin Velocity.

Well, the issue is that i am not able to load the WebContent fields that i have created on the begining. What i am doing is this:

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

## Obtengo todos WebContent de mi Estructura
#set ($articles = $journalArticleLocalService.getTemplateArticles($groupId, "12639"))

## Limpio la variable que me sirve para identificar el cambio de Articulo
#set ($lastArticleId = "")

<ul>

#foreach ($article in $articles)
#if (($lastArticleId == "" || $lastArticleId != $article.articleId)&&
($article.type == "Autor"))
#set ($lastArticleId = $article.articleId.substring(1))
#set ($resourcePrimKey = $article.resourcePrimKey)
#set ($lastArticle = $journalArticleLocalService.getJournalArticle($getterUtil.getLong($article.id)))

<li>$lastArticle</li>
#end
#end
</ul>

I couldnt see the data from the webcontent structure in any artcile. The result of $lastArticle variable is this:

lastArticle = {uuid=153d4904-e3a6-480e-838a-3bdb81f675f9, resourcePrimKey=12688, groupId=10182, articleId=/16032}

And in my structure i have other several fields thar are not present here, so i know i am not doing the things well, but i dont know where.

Could some one assit me to find a solution?

I couldnt do it with sax reader because i am on a https server, and that does not work with https.

Thanks in advance.
Eduardo Grotteschi, modifié il y a 10 années.

RE: Velocity - Template - Structure - LR6.2

New Member Publications: 22 Date d'inscription: 12/11/13 Publications récentes
any help?
thumbnail
James Falkner, modifié il y a 10 années.

RE: Velocity - Template - Structure - LR6.2

Liferay Legend Publications: 1399 Date d'inscription: 17/09/10 Publications récentes
Eduardo Grotteschi:
GM! after 2 weeks of workaround i need your help because i coulndt find a solution.

I couldnt see the data from the webcontent structure in any artcile. The result of $lastArticle variable is this:

lastArticle = {uuid=153d4904-e3a6-480e-838a-3bdb81f675f9, resourcePrimKey=12688, groupId=10182, articleId=/16032}

And in my structure i have other several fields thar are not present here, so i know i am not doing the things well, but i dont know where.

Could some one assit me to find a solution?

I couldnt do it with sax reader because i am on a https server, and that does not work with https.

Thanks in advance.


You'll never see the name/value pairs from your structure in the returned Java objects - the article itself is stored as a giant XML string in the database, and the low-level JournalArticle service and APIs don't actually parse that (that's left up to a higher software level when rendering the article).

So to get at the actual structure fields and their values, you'll have to do the parsing yourself using SAX (but you don't have to use http/https). So for example, this worked for me (I had to change a few of your constants to make it work in my environment):

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

## Obtengo todos WebContent de mi Estructura
#set ($articles = $journalArticleLocalService.getTemplateArticles($getterUtil.getLong($groupId), "15962"))

## Limpio la variable que me sirve para identificar el cambio de Articulo
#set ($lastArticleId = "")


#foreach ($article in $articles)
    #if (($lastArticleId == "" || $lastArticleId != $article.articleId))
        #set ($lastArticleId = $article.articleId.substring(1))
        #set ($resourcePrimKey = $article.resourcePrimKey)
        #set ($lastArticle = $journalArticleLocalService.getJournalArticle($getterUtil.getLong($article.id)))
        
        #set ($doc = $saxReaderUtil.read($lastArticle.getContentByLocale($lastArticle.getDefaultLocale())))
        
        #set ($rootEl = $doc.getRootElement())
        #foreach ($el in $rootEl.elements())
          #set ($dce = $el.element("dynamic-content"))
          <p>Name: $el.attributeValue("name")</p>
          <p>Value: $dce.getTextTrim()</p>
        #end
    #end
#end


NOTE that this code does NOT work for structures with deep nesting OR repeatable fields - for that, you'd need to add more iterations and deeper loops.

It's very instructive to "download" the article using the Liferay UI, and look at the underlying XML to understand how articles and structures are actually stored and processed in Liferay.
Eduardo Grotteschi, modifié il y a 10 années.

RE: Velocity - Template - Structure - LR6.2

New Member Publications: 22 Date d'inscription: 12/11/13 Publications récentes
James, if you ever come to Buenos Aires, you have a free "Asado" for you and your family.

Thanks a lot! emoticonemoticonemoticon
thumbnail
James Falkner, modifié il y a 10 années.

RE: Velocity - Template - Structure - LR6.2

Liferay Legend Publications: 1399 Date d'inscription: 17/09/10 Publications récentes
Eduardo Grotteschi:
James, if you ever come to Buenos Aires, you have a free "Asado" for you and your family.

Thanks a lot! emoticonemoticonemoticon


Hahaha, thanks for that! BTW I found another gem in the history of Liferay Blogs from Ray that you might be interested in.