cancel
Showing results for 
Search instead for 
Did you mean: 

Freemarker template that dumps all properties for a node

pmonks
Star Contributor
Star Contributor
G'day everyone,

I wrote this code some time ago and thought someone might find it useful - it's a Freemarker template that dumps all of the metadata properties for a node.  Currently it's setup to be configured as a Custom View for a document or space (ie. it's an Explorer UI Presentation Template), but it can be readily adapted for use in other Freemarker templates (eg. in a Web Script view) by copying just the macro.

<#macro dumpProperties node>
  <#if node.properties??>
  <table>
    <#list node.properties?keys as key>
    <#assign value = node.properties[key]>
    <tr>
      <td>${key}</td>
      <td>
      <#if value?is_date>
        ${value?datetime}
      <#elseif value?is_sequence>
        [
        <#list value as valueValue>
          ${valueValue},
        </#list>
        ]
      <#else>
         ${value}
      </#if>
      </td>
    </tr>
    </#list>
  </table>
  <#else>
    Node doesn't have properties.
  </#if>
</#macro>

<#if space??>
<strong>Properties for 'space':</strong>
<blockquote>
<@dumpProperties space/>
</blockquote>
</#if>

<#if person??>
<strong>Properties for 'person':</strong>
<blockquote>
<@dumpProperties person/>
</blockquote>
</#if>

<#if document??>
<strong>Properties for 'document':</strong>
<blockquote>
<@dumpProperties document/>
</blockquote>
</#if>

<#if companyHome??>
<strong>Properties for 'companyHome':</strong>
<blockquote>
<@dumpProperties companyHome/>
</blockquote>
</#if>

Note: currently it doesn't dump associations (either parent-child or peer-to-peer), but that would be a trivial enhancement.

Please reply to this thread if you have any questions / comments / suggestions / improvements / etc.

Cheers,
Peter
3 REPLIES 3

richard_im
Champ in-the-making
Champ in-the-making
very cool

eddiem
Champ in-the-making
Champ in-the-making
Much appreciated..
Eddie

tommorris
Champ in-the-making
Champ in-the-making
Hi there.

You may experience problems if you've got boolean properties on your object.

I've ammended the file to include the 'is_boolean' test:


    <#macro dumpProperties node>
      <#if node.properties??>
      <table>
        <#list node.properties?keys as key>
        <#assign value = node.properties[key]>
        <tr>
          <td>${key}</td>
          <td>
          <#if value?is_date>
            ${value?datetime}
          <#elseif value?is_boolean>
            ${value?string("yes", "no")}
          <#elseif value?is_sequence>
            [
            <#list value as valueValue>
              ${valueValue},
            </#list>
            ]
          <#else>
             ${value}
          </#if>
          </td>
        </tr>
        </#list>
      </table>
      <#else>
        Node doesn't have properties.
      </#if>
    </#macro>

    <#if space??>
    <strong>Properties for 'space':</strong>
    <blockquote>
    <@dumpProperties space/>
    </blockquote>
    </#if>

    <#if person??>
    <strong>Properties for 'person':</strong>
    <blockquote>
    <@dumpProperties person/>
    </blockquote>
    </#if>

    <#if document??>
    <strong>Properties for 'document':</strong>
    <blockquote>
    <@dumpProperties document/>
    </blockquote>
    </#if>

    <#if companyHome??>
    <strong>Properties for 'companyHome':</strong>
    <blockquote>
    <@dumpProperties companyHome/>
    </blockquote>
    </#if>