cancel
Showing results for 
Search instead for 
Did you mean: 

access property name with freemarker

eldi
Champ in-the-making
Champ in-the-making
Hello,

1) This works fine :

   <#– Get a list of all the property names for the document –> 
                      <#assign props = doc.properties?keys> 
                      <#list props as t>
                         <#– If the property exists –>
                         <#if doc.properties[t]?exists>
                               <#– If it is a date, format it accordingly–>
                               <#if doc.properties[t]?is_date>
                                     ${t} = ${doc.properties[t]?date}
                              
                               <#– If it is a boolean, format it accordingly–>
                               <#elseif doc.properties[t]?is_boolean>
                                     ${t} = ${doc.properties[t]?string("yes", "no")}
                              
                               <#– Otherwise treat it as a string –>
                               <#else>
                                     ${t} = ${doc.properties[t]}                                     
                               </#if>
                         </#if>
                      </#list>

OUTPUT is :

{http://www.alfresco.org/model/content/1.0}creator = admin   

{http://www.alfresco.org/model/content/1.0}author = eok

…etc


2) i want only print  :

creator = admin
author = eok
…etc

and not '{http://www.alfresco.org/model/content/1.0}…', if i write ]{t.name}, i get an error, why ?
What should i write to get the property name only ?


Thank you.
2 REPLIES 2

abarisone
Star Contributor
Star Contributor
Hi,
try this one <blockcode>properties:    <#list node.properties?keys as t>
            <#– If the property exists –>
                <#if (node.properties[t]?exists)>
                   <#– If it is a date, format it accordingly–>
                   <#if node.properties[t]?is_date>
                   ${t?substring(t?last_index_of("}")+1)}:"${node.properties[t]?string("dd-MM-yyyy")}"
                   <#– If it is a boolean, format it accordingly–>
                   <#elseif node.properties[t]?is_boolean>
                   ${t}:"${node.properties[t]?string("yes", "no")}"
                   <#– If it is a sequence–>
                   <#elseif node.properties[t]?is_sequence>
                   ${t?substring(t?last_index_of("}")+1)}:[<#list node.properties[t] as item>
                            ${item}<#if item_has_next>,</#if>
                            </#list>]
                   <#– Otherwise treat it as a string –>
                   <#else>
                   ${t?substring(t?last_index_of("}")+1)}:"${node.properties[t]?js_string}"
                   </#if>
                   <#if t_has_next>,</#if>
                </#if>
             </#list></blockcode>

Regards,
Andrea

eldi
Champ in-the-making
Champ in-the-making
Hi Andrea,

thank you very much! it works fine.
I would prefer to use some defaultsy tax like 't.name' or whatever instead of a susbtring'
Does spmeone know on how to proceed this?