cancel
Showing results for 
Search instead for 
Did you mean: 

Correct use of processTemplate

lordzoster
Champ in-the-making
Champ in-the-making
Hallo
I have an RTF freemarker template which I fill with some arbitrary data, and then save into a folder different than origin.
The file saves correctly but without any modification - just the original template.
Moreover, I don't understand the meaning of the node against which I am expected to call the method, the "node" of "node.processTemplate" syntax.

Here is the code:

var template = search.findNode("workspace://SpacesStore/027f4dd7-1d03-4fb2-95bd-80a2d48f6af0");
var node = search.findNode("workspace://SpacesStore/0c1b9534-17a8-41e6-9352-43af7f9f0b69"); // which should it be?
var destDir = search.findNode("workspace://SpacesStore/79302af2-abb2-493a-87ed-885cfe5dd20e");

var args = new Array();

args["certiq"] = "Some text here";
var result = node.processTemplate(template, args);

var outputFile = destDir.createFile("output.rtf");
outputFile.content = result;
In the template there are occurrences both of ${args["certiq"]} (double quotes, as of Freemarker documentation) and ${args['certiq']} (single quotes, as of Alfresco Wiki Javascript API Cookbook samples).

Any help will be greatly appreciated!
3 REPLIES 3

mitpatoliya
Star Collaborator
Star Collaborator
save outputFile after operation
outputFile.save();

and may be you also need to change this
outputFile.content.content=result;

Thank you for replying, the output file gets already created anyway.
The point is that I cannot understand the nodes involved, even in the Javascript API cookbook example:
<em>Executes a template from the repository against the current Document node:</em>
<javascript>
var template = "<h3>Document name is ${document.name}</h3>" +
               "The ID argument: ${args['id']}";
var args = new Array()
args["id"] = "01234-56789";
var result = document.processTemplate(template, args);
// save the template result content to a new node in my home space
var outputFile = userhome.createFile("output.txt");
outputFile.content = result;
</javascript>

Here we have:
1. a template;
2. an outputFile;
3. and a document "against which the template is processed". What does this mean?
What is the meaning of "executing a template against a Document node"? What's the role of the Document node the template is processed against to?
Moreover, the outputFile is identical to the template: placeholders are not getting processed, they are output as is.

mitpatoliya
Star Collaborator
Star Collaborator
Template+Model=New Output File
This is the ideal scenario for any template processing language.
Now in Alfresco "document" is predefined object in alfresco context which points to current node which is being processed. So, in this case it is just being used to access APIs related to template processing.