cancel
Showing results for 
Search instead for 
Did you mean: 

How is TemplateNode configured into alfresco explorer ?

zengqingyi12
Champ in-the-making
Champ in-the-making
I know alfresco are implemented with spring framework.
And there is a preview template function in alfresco explorer: 
User just need to create a freemarker template file, then system can generate the content by itself.
There is a buildin object called "document" in freemarker template, I think it is from TemplateNode class.
But after I searched all the xml file, I didn't find anything that configure the TemplateNode to be a bean of spring framework.
So I just want to know how can TemplateNode be integrated into the template framework in alfresco explorer and expose the data to FreeMarker template.

Thanks in advance ! Hope someone gets me.

EDIT:
If someone doesn't know what I am saying, please have a look at following:
There are several "TemplateNode" objects that wrap common Alfresco Node objects to provide an rich OO layer suitable for scripting usage.
I just want to know how these "TemplateNode" wrap common Alfresco Node objects ?  How and where to configure them ?
2 REPLIES 2

savic_prvoslav
Champ on-the-rise
Champ on-the-rise
HI, you could read a bit down on that page and you would find:

<r:template template="alfresco/templates/example.ftl" model="#{MyBean.templateModel}" />
Example Bean code to return a model:

 /**
   * Returns a model for use by a template on the Document Details page.
   *
   * @return model containing current document and current space info.
   */
  public Map getTemplateModel()
  {
     HashMap model = new HashMap(1, 1.0f);
    
     TemplateNode documentNode = new TemplateNode(getDocument().getNodeRef(), this.nodeService);
     model.put("mydocument", documentNode);
    
     return model;
  }

I hope that this was helpful .

zengqingyi12
Champ in-the-making
Champ in-the-making
Where did you see that code ? What I saw is :
  public Map getTemplateModel()
  {
     Map<String, Object> model = new HashMap<String, Object>(4, 1.0f);
    
     model.put("document", getDocument().getNodeRef());
     model.put("space", this.navigator.getCurrentNode().getNodeRef());
     model.put(TemplateService.KEY_IMAGE_RESOLVER, imageResolver);
    
     return model;
  }
and in this code, no TemplateNode is used ?
I think the version above is for Alfresco 2.1, but in 1.4 and 2.0, things work as you said.
I just confused, in Alfresco, why use code above, and how it works ?  (http://wiki.alfresco.com/wiki/Template_Guide#Examples, this is where I read)

EDIT:
If you wish to expose Node objects in your model, it is recommended that you follow the same pattern as used by the default model and simply add NodeRef instances to your model, as these objects automatically get converted to the appropriate template model types by the various engines to provide the API described above. Any other objects can be added to your custom model as you see fit - they will not get converted by the template engine if they are not recognised.
How does the automatic conversion  work ?
h