Apply template to document node using Javascript API
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2007 04:14 PM
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?
Could anyone enlighten me on how you might go about this?
Labels:
- Labels:
-
Archive
4 REPLIES 4

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2007 10:48 AM
Yes you can. You can execute a template string directly:
and you can execute a template that already exists in the repo, such as:
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
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2007 12:04 PM
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?
This does not seem to be the case. There are no Javascript errors, but no visible results either… any guidance?

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2007 12:24 PM
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
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

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2008 02:38 PM
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.
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.
