Fórum

Can't get dynamic-element

Adrian Pol, modificado 7 Anos atrás.

Can't get dynamic-element

Junior Member Postagens: 49 Data de Entrada: 14/03/17 Postagens Recentes
i have a dinamic-element in custom structure:
<dynamic-element dataType="string" indexType="keyword" localizable="true" name="Destino" readOnly="false" repeatable="false" required="false" showLabel="true" type="radio" width="">
<dynamic-element name="option6738" type="option" value="Europa">
<meta-data locale="es_ES">
<entry name="label">
<![CDATA[Europa]]>
</entry>
</meta-data>
</dynamic-element>
<dynamic-element name="option13955" type="option" value="america">
<meta-data locale="es_ES">
<entry name="label">
<![CDATA[America]]>
</entry>
</meta-data>
</dynamic-element>
<dynamic-element name="option13956" type="option" value="africa">
<meta-data locale="es_ES">
<entry name="label">
<![CDATA[Africa]]>
</entry>
</meta-data>
</dynamic-element>
<meta-data locale="es_ES">
<entry name="label">
<![CDATA[Destino]]>
</entry>
<entry name="predefinedValue">
<![CDATA[[""]]]>
</entry>
<entry name="tip">
<![CDATA[]]>
</entry>
</meta-data>
</dynamic-element>

i'm doing a template with velocity and a want get Destino but i can't i write $destino and don't return nothing, i don't know what is appen, how get the data ["europe"]. I've do yesterday but i don't remenber how do today...
thumbnail
Danielle Ardon, modificado 7 Anos atrás.

RE: Can't get dynamic-element

Junior Member Postagens: 37 Data de Entrada: 06/06/16 Postagens Recentes
You have to 'get' the data:

$Destino.getData()
Adrian Pol, modificado 7 Anos atrás.

RE: Can't get dynamic-element

Junior Member Postagens: 49 Data de Entrada: 14/03/17 Postagens Recentes
not work emoticon output is $Destino.getData()
thumbnail
Danielle Ardon, modificado 7 Anos atrás.

RE: Can't get dynamic-element

Junior Member Postagens: 37 Data de Entrada: 06/06/16 Postagens Recentes
That is strange.

How are you creating this template? In the template editor of the portal?
And in which liferay version? (6.2, 7)

If you are using the portal template editor, are you sure the template language is set to velocity and not freemarker?

Can you show the entire template?
Adrian Pol, modificado 7 Anos atrás.

RE: Can't get dynamic-element

Junior Member Postagens: 49 Data de Entrada: 14/03/17 Postagens Recentes
the version is 6.2.2 and yes i'm using the template editor of the portal and the language is velocity

<style>

div .rowButton {
border-bottom: 1px solid #DDD;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: rgb(221, 221, 221)
}

div .bodyArticle {
margin-left: 5%;
margin-top: 5px;
}

#logoPowered {
margin-left: 80%;
font-size: 9px;
}

</style>

<!-- MACROS -->

<!-- Devuelve el nombre de la pagina
#set($layout = $layoutService.getLayout($layoutLong))
#set ($pageName = $layout.getName($locale)) -->

<!-- Devuelve el instance de la pagina -->
#macro (getId)
#set ($instance = $themeDisplay.getPortletDisplay().getId())
#set($indexFinId = $instance.indexOf("E_") + 2)
#set($id = $instance.substring($indexFinId, $instance.length()))
$id
#end

<!-- Devuelve la url actual con http:// -->
#macro(getActualUrl)
#set($actualUrl = $currentURL.indexOf("?"))
#set($actualUrl = $currentURL.substring(0, $actualUrl))
$actualUrl
#end

<!-- Cuerpo de la plantilla -->
#if (!$entries.isEmpty())
#set ($x = 0)

#foreach ($curEntryin $entries)
#if ($x == 0)
<!-- Tendremos que usar trim mas abajo ya qu ela macro devuelve
el valor con espacios en blanco -->
#set($actualUrl = "#getActualUrl()")
#set ($id = "#getId()")

$themeDisplay.getAccount()
$themeDisplay.getDefaultUser()
$themeDisplay.getPortalURL()

#set ($assetRenderer = $curEntry.getAssetRenderer())
<div class="rowButton" >
<h1><a href="$actualUrl.trim()/-/asset_publisher/$id.trim()/content/$entry.getTitle($locale)">
$assetRenderer.getTitle(locale) </a></h1>
</div>
Destino: $Destino.getData() </br>
Display Date: $entry.getCreateDate() </br>

<div class="bodyArticle" span3>

$entry.getDescription($locale)
</div>

#end
#set ($x = $x + 1)
#end
#else
<div class="alert alert-info" id="yui_patched_v3_11_0_1_1490100453486_9809"> No hay resultados. </div>
#end
Adrian Pol, modificado 7 Anos atrás.

RE: Can't get dynamic-element

Junior Member Postagens: 49 Data de Entrada: 14/03/17 Postagens Recentes
I do not know if it will have something to do but it's a template ADT, int basic template works perfectily.
thumbnail
Danielle Ardon, modificado 7 Anos atrás.

RE: Can't get dynamic-element (Resposta)

Junior Member Postagens: 37 Data de Entrada: 06/06/16 Postagens Recentes
Ah yes no wonder, you can't use variables like that in ADT'S.
An adt is not connected to a specific structure, so it doesn't know the variable names of certain articles.
I presume you use the adt for an asset publisher? An asset publisher can display different structures/ content types in one view so you can't use the same language.

You can do it like this:
 #foreach ( $entry in $entries )
		#set ( $renderer = $entry.getAssetRenderer() )
                #set ( $className = $renderer.getClassName() )

        #if ( $className == "com.liferay.portlet.journal.model.JournalArticle" )
            #set ( $article = $renderer.getArticle() )
	    #set ( $document = $saxReaderUtil.read($article.getContent()) )
            #set ( $rootElement = $document.getRootElement() )

            #set ( $xPathSelector = $saxReaderUtil.createXPath("dynamic-element[@name='Destino']") )
            #set ( $Destino = $xPathSelector.selectSingleNode($rootElement).getStringValue())
 #end ##class
#end ##foreach

But don't forget to check whether the entry is a journalarticle before you do these things, otherwise you will get very strange results and errors