Message Boards

How to get friendly url of Internal-page field in ADT in DXP 7.3

thumbnail
Ernesto Melian, modified 2 Years ago.

How to get friendly url of Internal-page field in ADT in DXP 7.3

New Member Posts: 8 Join Date: 9/6/17 Recent Posts

Hello team
I´m trying to create an Aplication Display Template (ADT) in Liferay DXP 7.3 reusing code made in velocity that we have running in Portal 6.2, but the results obtained are not the same, that is, we are not obtaining the same values.

For example, we have web contents that use a structure that contains a Documents and media field (documents-and-media), but when obtaining the data from this field, instead of being a url that we can use in the src attribute of a image tag, we get a character string in object format:

{"classPK":47068,"groupId":"43835","title":"article (1).jpg","type":"document","uuid":"9718236c-8b80-a729-6258-15033417b53a"}

Similar happens with the fields of internal pages (ddm-link-to-page) that we could not obtain a friendly url to use in a <a> tag, getting the same string in an object format.

Could you help me or guide me on how to go through the fields of the content structure when creating an ADT? It can be both with freemarker and velocity.

We attach the ADT created so that you can see the code that we currently use. Lines 13 and 14 are the ones that obtain the data from the previously commented fields.

We look forward.

ADT Code:

#set($aplicaciones = [])
#set($layoutLocalService = $serviceLocator.findService("com.liferay.portal.service.LayoutLocalService"))

#foreach ($entry in $entries)
	#set($renderer = $entry.getAssetRenderer())
	#set($className = $renderer.getClassName())
	#if( $className == "com.liferay.journal.model.JournalArticle" )
		#set($article = $renderer.getArticle())	
		#set($doc = $saxReaderUtil.read($article.getContent()))
		#set($rootElement = $document.getRootElement())

		#set($nombre = $doc.valueOf("(//dynamic-element[@name='nombre_app'])/dynamic-content/text()"))
		#set($icono = $doc.valueOf("(//dynamic-element[@name='icono_app'])/dynamic-content/text()"))
        #set($pagina = $doc.valueOf("(//dynamic-element[@name='url_app'])/dynamic-content/text()"))
		#set($resumen = $doc.valueOf("(//dynamic-element[@name='resumen'])/dynamic-content/text()"))
        #set($detalles_tecnicos = $saxReaderUtil.createXPath("//dynamic-element[@name='d_tecnicos']").selectNodes($doc.getRootElement()))
		
        #set($tiendas = [])
		#foreach ($detail in $detalles_tecnicos)
			#set($sistema = $detail.valueOf("(//dynamic-element[@name='os'])[$velocityCount]/dynamic-content/text()"))
			#set($link = $detail.valueOf("(//dynamic-element[@name='url'])[$velocityCount]/dynamic-content/text()"))
			#set($null = $tiendas.add({
	            "sistema":$sistema,
	            "link":$link
	        }))
		#end

		#set($app = {
			"nombre":$nombre,
			"icono":$icono,
			"resumen":$resumen,
			"pagina":$pagina,
			"tiendas":$tiendas
		})
		#set($null = $aplicaciones.add($app))
	#end
#end

<div class="container contenedor-aplicaciones">
    <div class="row">
        #foreach($app in $aplicaciones)
            <div class="col-sm columna-app">
                <a href='$app.pagina' class="link-app">
                    <div class="icono-app">
                        <img src='$app.icono'>
                    </div>
                    <h4 class="">$app.nombre</h4>
                    #foreach($store in $app.tiendas)
                        <a href="$store.link">$store.sistema</a>
                    #end
                </a>
            </div>
        #end
    </div>
</div>