AnsweredAssumed Answered

Template Question

Question asked by rich.weiskopf on Jul 9, 2006
1.   Generated codeBase: rev36 from svn
   Windows XP

2.   Created a template genModelNames.ftl (these 2 lines were its only contents):

   ${document.properties.name}

   ${document.properties.modelDirectoryName}


2.   Using jsp example from http://wiki.alfresco.com/wiki/Template_Guide, created a jsp, and put it into a dialog

   <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
   <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
   <%@ taglib uri="/WEB-INF/alfresco.tld" prefix="a" %>
   <%@ taglib uri="/WEB-INF/repo.tld" prefix="r" %>

   <r:template template="alfresco/templates/genModelNames.ftl" model="#{TestTemplateBB.templateModel}"



3.   Created a TestTemplateBB per example:

     public Map getTemplateModel()
     {

        HashMap model = new HashMap(1, 1.0f);
        TemplateNode documentNode = new TemplateNode(browseBean.getDocument().getNodeRef(),
              this.serviceRegistry,null);
        model.put("document", documentNode);
        return model;
     }



4.   Received error message when accesing genModelNames.ftl:
   Expression document.properties.modelDirectoryName is undefined on line 4, column 3 in alfresco/templates/genModelNames.ftl.
   The problematic instruction:
   ———-
   ==> ${document.properties.modelDirectoryName} [on line 4, column 1 in alfresco/templates/genModelNames.ftl]


   Note: Also received this error where accessing  from 'Preview in template'

5.   Modified genModelNames.ftl (copied table snippet from wiki page):

   ${document.properties.name}

    <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>


6.   Got results of:
   testmodel
   {http://www.drjb.com/model/codegeneration/1.0}modelDirectoryName = testmodel


7.   Removed final from TemplateNode so it could be extended, and created MyTemplateNode

8.   Overrode getProperties and replaced:

     this.properties.put(qname.toString(), propValue);

     -with-

          this.properties.put(qname.getLocalName(), propValue);

9.   Executed genModelNames.ftl as defined in #5
   a.   It accessed document.properties.modelDirectoryName correctly; returning value of: testmodel

   b.   It also prepended the localname with the cm: URI
      {http://www.alfresco.org/model/content/1.0}modelDirectoryName = testmodel


10.   Is there someplace to register custom model URI's so freemarker can deal with them without resorting to the localname?

Thanks,
Rich

Outcomes