Foros de discusión

Repeatable Fields from Web content in ADT

Pierre-François Fiat, modificado hace 7 años.

Repeatable Fields from Web content in ADT

New Member Mensajes: 7 Fecha de incorporación: 12/02/15 Mensajes recientes
Hello,

I would like to display repeatable fields in my ADT.
My Web Content has the following structure:
--contact : repeatable="true"
---- telephone (inside contact) : repeatable="true"

I would like to display the content of all the "contact" fields with all the subfields "telephone" linked to them.

my web content has the following data :
-- contact = A
---- telephone=0000 / telephone=0001
-- contact = B
---- telephone=0002
I would like to see
A 0000 0001 B 0002


So far, I can detect the nodes that contains Contact and Telephone but I can not display the content of the fields:

<#list entries as entry>
	<#assign assetRenderer = entry.getAssetRenderer()>
	<#assign docXml = saxReaderUtil.read(assetRenderer.getArticle().getContent()) />
	<#assign contacts = docXml .getRootElement().selectNodes("//dynamic-element[@name='contact']") />

	<#list contacts as con>
		1
		<#assign telephones = con.selectNodes("//dynamic-element[@name='telephone']") />
		<#list telephones as tel>
			2
		<!--#list-->
	<!--#list-->
<!--#list-->


I have
1 2 2 2 1 2 2 2
for a result so I deduce I retrieve correctly the nodes for contact but not for telephone.

I am using Liferay 7 GA2.
Does anyone know how to display the data ?
Thank you by advance emoticon
Pierre-François Fiat, modificado hace 7 años.

RE: Repeatable Fields from Web content in ADT

New Member Mensajes: 7 Fecha de incorporación: 12/02/15 Mensajes recientes
I have found the first part of my answer :

to display the data of a node :

&lt;#assign text = con.elementText("dynamic-content") /&gt; ${text}


Now I need to display the repeatable fields inside repeatable fields.
Does someone knows how to do it ?
Pierre-François Fiat, modificado hace 7 años.

RE: Repeatable Fields from Web content in ADT (Respuesta)

New Member Mensajes: 7 Fecha de incorporación: 12/02/15 Mensajes recientes
Sorry for the monologue...

To get the fields from the the parent node I did :

&lt;#assign subfields = con.elements("dynamic-element")&gt;


Of course this gives me all the sub-fields (if the web content structure has more than just telephone). In order to parse to get only the "telephone" I did this way,

&lt;#list subfields as subfield &gt;
 &lt;#if subfield.attributeValue("name") == "telephone"&gt;
  &lt;#assign text = subfield.elementText("dynamic-content") /&gt; ${text}
 <!--#if-->
<!--#list-->


I hope it will help someone one day emoticon
And if you know cleaner code, please please SHARE IT !
Salvatore Taddeo, modificado hace 3 años.

RE: Repeatable Fields from Web content in ADT

New Member Mensajes: 5 Fecha de incorporación: 10/07/19 Mensajes recientes
Thanks Pierre, You helped me a lot!