cancel
Showing results for 
Search instead for 
Did you mean: 

accessing custom properties with JavaScript

paullewon
Champ in-the-making
Champ in-the-making
I have a custom aspect defined as follows:

    <aspects>
     
      <aspect name="cu:sourceInformation">
         <title>Source Information</title>
         <properties>
            <property name="cu:sourceTitle">
               <type>d:text</type>
            </property>
            <property name="cu:imprint">
               <type>d:text</type>
            </property>
            <property name="cu:mcode">
               <type>d:text</type>
            </property>
            <property name="cu:isbn">
               <type>d:text</type>
            </property>
            <property name="cu:isbn13">
               <type>d:text</type>
            </property>
         </properties>
      </aspect>
    
   </aspects>
  
And I have a .ftl for pulling properties as a pipe-delimited output as follows:

<#list folder.children as child><#if child.isDocument>${child.name}|${xmldate(child.properties.modified)}|${child.properties.description!""}|${child.properties.creator}|${child.properties["cu:isbn"]}<br /></#if></#list>

It works with everything but the last ${child.properties["cu:isbn"]} reference, which is the only custom property in it. When I add that custom property reference I get the following error:

    Error during processing of the template 'Expression child.properties["cu:isbn"] is undefined on line 1, column 172 in propertysheet.get.html.ftl.'. Please contact your system administrator.
I've tried quite a number of syntax variations on that reference. What am I missing?

Thanks,

Paul
5 REPLIES 5

kevinr
Star Contributor
Star Contributor
FreeMarker is very strict on 'null' values - if that property does not exists on a document and returns 'null' it will cause that error I think.

I've not tried the syntax you are using, but you have something similar for 'description':
${child.properties.description!""}

which i assume means to display "" if the value is missing i.e. null. Can you try something similar for the 'cu:isbn' value?

We normally use the ?exists built-in to filter out missing values.

Thanks,

Kevin

paullewon
Champ in-the-making
Champ in-the-making
Kevin,

Thank you. The following syntax works:

${child.properties["cu:isbn"]!""}

As does:

<#if child.properties["cu:isbn"]?exists>${child.properties["cu:isbn"]}<#else></#if>

Thanks again,

Paul

kevinr
Star Contributor
Star Contributor
Excellent. Nice to learn about that syntax so i can use it Smiley Happy

Thanks,

Kevin

marãƒâ_a
Champ in-the-making
Champ in-the-making
Hello,
I’m trying to show all the aspects of a space. I’ve extended the model adding new aspects to all the items in a space. This is what I meant:

   Name:   Expediente 1
       Title:   Expediente 1
       Description:   
       Creator:   admin
       Created Date:   5 September 2007 14:54
       Modifier:   admin
       Modified Date:   5 September 2007 14:56
   
     Propiedades del expediente
       Identificador del expediente:   1
       Procedimiento:   Reclamaci
       Fecha de entrada:   1 June 2007
       Fecha de fin:   
       Cuantia en euros:   1200000
       Asunto:   fff

I’ve added an aspect "Propiedades del expediente" with all the properties showed below.

I want to have a template to show all this properties, and this is what I’ve tried:

-   I’ve tried to show space.aspects
-   I’ve tried to show space.properties
-   I’ve tried to guess if the space.hashaspect called, for example “customSmiley Tonguerocedimientoâ€

kevinr
Star Contributor
Star Contributor
The space.aspects simply returns the names of all the aspects that have been applied to a node - it does not return the values of the properties that are defined by those aspects. The node.properties map contains all the properties that have been set a value on that node - if they have not been set, then will not be in the map.

Something like node.properties["custom:myprop"] will show the value of the property called "custom:myprop" - you do not need to reference the name of the aspect at all. You just reference the properties you need directly and it will work. This example (copied from the Template wiki guide page) shows all properties for a node:

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

Thanks,

Kevin