How to pass values from javascript to custom template file in data dictionary?

cancel
Showing results for 
Search instead for 
Did you mean: 
vikash_patel
Established Member

How to pass values from javascript to custom template file in data dictionary?

Jump to solution

Hi,

I have created a webscript and this is the code of js file.

var fileNode=companyhome.childByNamePath("Data Dictionary/Node Templates/test.html.ftl");
var doc1=companyhome.createFile("testtemplate123.doc");
var props = new Array(1);
props["docname"] = "tesstttt";
var content=doc1.processTemplate(fileNode,props);
doc1.properties.content.content= content;
doc1.mimetype = "application/msword";
doc1.save();‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

And a custom template file in Data Dictionary/Node Templates/test.html.ftl.

<html>
<head>
<style type="text/css"><!--
body
{
font-family: Arial, sans-serif;
font-size: 14px;
color: #4c4c4c;
}
a, a:visited
{
color: #0072cf;
}
-->
</style>
</head>
<body bgcolor="#dddddd">
<table width="100%" cellpadding="20" cellspacing="0" border="0" bgcolor="#dddddd">
<tr>
<td width="100%" align="center">
<table width="70%" cellpadding="0" cellspacing="0" bgcolor="white" style="background-color: white; border: 1px solid #aaaaaa;">
<tr>
<td width="100%">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td style="padding: 10px 30px 0px;">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<div style="font-size: 14px; margin: 12px 0px 24px 0px; padding-top: 10px; border-top: 1px solid #aaaaaa;">
<p>Hi,Hello</p>
</div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<div style="border-top: 1px solid #aaaaaa;"> </div>
</td>
</tr>
<tr>
<td style="padding: 0px 30px; font-size: 13px;">
To find out more about Alfresco visit <a href="http://www.alfresco.com">http://www.alfresco.com</a>
</td>
</tr>
<tr>
<td>
<div style="border-bottom: 1px solid #aaaaaa;"> </div>
</td>
</tr>
<tr>
<td style="padding: 10px 30px;">
</td>
</tr>

</td>
</tr>
</table>
</body>
</html>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

This code is working fine and i am able to create a file as shown in attached screen shot.

How can I pass my variables from javascript to Templates(ftl) file?
and how to access these variables in template(ftl) file?

1 Solution

Accepted Solutions
kalpesh_c2
Senior Member

Re: How to pass values from javascript to custom template file in data dictionary?

Jump to solution

Vikas, you can try passing parameters using args parameter (map) in processTemplate

processTemplate(template, args)

processTemplate | Alfresco Documentation 

Let me know if this works.

Thanks,

Kalpesh

ContCentric

View solution in original post

6 Replies
romschn
Senior Member

Re: How to pass values from javascript to custom template file in data dictionary?

Jump to solution

Have you tried setting up values in model object from JS file for example, model.name="ABC" and in ftl access it as ${name}.

Hope this helps.

vikash_patel
Established Member

Re: How to pass values from javascript to custom template file in data dictionary?

Jump to solution

yes, It is not working.

romschn
Senior Member

Re: How to pass values from javascript to custom template file in data dictionary?

Jump to solution

If I am understanding correctly then, Looks like you are trying to replicate the same thing as done during email sending. However, while email send when you set up the template model, it resolves values at the runtime during mail action. Here, from one JS file you are trying to populate values in a static html template which in my opinion would not be possible straight away. You may need to take a look at processTemplate and see if you can customize it passing the values for the variables in the template.

Hope this helps.

vikash_patel
Established Member

Re: How to pass values from javascript to custom template file in data dictionary?

Jump to solution

thank you, sir
let me try it with processTemplate.

kalpesh_c2
Senior Member

Re: How to pass values from javascript to custom template file in data dictionary?

Jump to solution

Vikas, you can try passing parameters using args parameter (map) in processTemplate

processTemplate(template, args)

processTemplate | Alfresco Documentation 

Let me know if this works.

Thanks,

Kalpesh

ContCentric

vikash_patel
Established Member

Re: How to pass values from javascript to custom template file in data dictionary?

Jump to solution

Thank you, Sir It is working.

var args = new Array(1);
args["hello"] = "78978879";
var content=doc1.processTemplate(fileNode,args);
doc1.properties.content.content= content;

now I can access these variable using ${args.hello}