cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing node object in freemarker template

alf_ecm
Champ in-the-making
Champ in-the-making
I want to make an ajax call to a webscript in a freemarker template. Is there any example or guidelines about how to do this?

Is it possible to access node object and its properties such as original id into freemarker template?

Thanks
7 REPLIES 7

mitpatoliya
Star Collaborator
Star Collaborator
Yes you can access those things in ftl provided it is being passed through model from javascript.
Are you talking about stand alone js?
http://wiki.alfresco.com/wiki/FreeMarker_Template_Cookbook

For ajax call you can include script tags which will hold javascript function within which you can have ajax call.

alf_ecm
Champ in-the-making
Champ in-the-making
Thanks that worked for me. Still not sure how to access node object.

mitpatoliya
Star Collaborator
Star Collaborator
If you see this example in that link



<table>
<#list companyhome.children as child>
    <#if child.isContainer>
       <tr>
          <td><img src="/alfresco${child.icon32}"></td>
          <td><b>${child.properties.name}</b> (${child.children?size})</td>
       </tr>
    </#if>
</#list>
</table>


"companyhome.children" return you list of nodes which you are iterating. So, this is nothing but node only.

alf_ecm
Champ in-the-making
Champ in-the-making
My freemarker template is for custom form control for alfresco share.

Neither companyhome nor node object is available in freemarker template.

I get companyhome and node not defined error.

Those objects will be available in alfresco repository context only not in share context.The example which you had checked on that link are related to alfresco repo context ftl.
So, for share flow is like you have to pass everything from javascript controller which in turn call alfresco repository webscripts and get data. then pass that to ftl through model.

alf_ecm
Champ in-the-making
Champ in-the-making
I have found the answer. ${form.arguments.itemId} gives me workspace://SpacesStore/a7288a57-ae57-4345-8c8b-ce798266a210

Now i need to get only id bit a7288a57-ae57-4345-8c8b-ce798266a210

kaynezhang
World-Class Innovator
World-Class Innovator
You can use Freemarker substring function.
http://freemarker.org/docs/ref_builtins_string.html