cancel
Showing results for 
Search instead for 
Did you mean: 

Apply template to document node using Javascript API

rbelisle
Champ in-the-making
Champ in-the-making
It looks like you can apply a template to a node using the Javascript API through the ScriptAction api???

Could anyone enlighten me on how you might go about this?
4 REPLIES 4

kevinr
Star Contributor
Star Contributor
Yes you can. You can execute a template string directly:
   var result = document.processTemplate("this is a freemarker template executed by ${person.properties.userName}");‍‍‍

and you can execute a template that already exists in the repo, such as:
   var template = companyhome.childByNamePath["/Data Dictionary/Presentation Templates/doc_info.ftl"];   var result = document.processTemplate(template);‍‍‍‍

There's a lot you can do with this! As the first example shows, you can construct the template itself in javascript code, you can also load up template content, modify it if you wish and execute it on the fly.

Hope this helps,

Kevin

rbelisle
Champ in-the-making
Champ in-the-making
I tried the examples you provided. I was expecting that if I created a script file in the 'Scripts' space, then from the details page of a document, did a 'Run Action' and executed the script, that the template would be reflected in the current document web page view. (ie. the template would be applied and the result would be displayed in the webpage).

This does not seem to be the case. There are no Javascript errors, but no visible results either… any guidance?

kevinr
Star Contributor
Star Contributor
No the Run Action facility is not designed to display any results from scripts/templates. It was added long before the script+templates facilities were implemented. I suggest you raise a JIRA request for this feature.

It is possible to execute any script and display the result using the command servlet:
http://wiki.alfresco.com/wiki/URL_Addressability#Script_Command_Processor
that doesn't help you in the Run Action case though.

Thanks,

Kevin

tdahlgren
Champ in-the-making
Champ in-the-making
Was a JIRA request ever created for this?  (I performed a quick search that did not appear to turn up a case.)

P.S.  It would be helpful if the JavaScript Wiki and/or examples make it very clear that results are not returned when the script is called from the Run Action facility.