cancel
Showing results for 
Search instead for 
Did you mean: 

Access to JavaScript API from .ftl

damiar
Champ in-the-making
Champ in-the-making
Hi all,

I want to know if the user that is currently executing the webscript has "Write" permission over some folder.

Here is some code of I would like to do (FTL):

<folderStructure>
  <rootName><![CDATA[${rootName}]]></rootName>
  <rootChildren>     
      <#list nodes as child>
        <child>
          <name><![CDATA[${child.name}]]></name>
           <readOnly><![CDATA[${ child.hasPermission("Write") }]]></readOnly>
        </child>
      </#list>
   </rootChildren>
</folderStructure>

Of course this code does not work (syntax error on child.hasPermission), but I cannot figure out of what should I do in order to know if the user can or cannot write on a folder.

I've tried to itearate over the "nodes" array that I'm using on the FTL and manually set a custom property that tell me if the user can write on the folder, here's the code:


  for each (var child in children) {
    logger.log(child.name + " : " + child.hasPermission("Write"));
    child.properties.readOnly = !child.hasPermission("Write");
  }
  model.nodes = children;

But the problem is that if the user cannot write on a folder (I mean the user has no write permissions) the line "child.properties.readOnly = …"  won't work. Actually I'm getting an error in the FTL that tells me that the property readOnly doesn't exists if the user cannot write in the folder, but the scripts works fine if he can write on the them.

What can I do? Any ideas?

Thanks!
2 REPLIES 2

mikeh
Star Contributor
Star Contributor
Freemarker tends to want strings in situations like that, so try:
child.hasPermission("Write")?string

Thanks,
Mike

damiar
Champ in-the-making
Champ in-the-making
Thanks a lot! It works! Smiley Happy