executeTemplate not working as expected

I’ve tried using the following template fields in my DOCX file:

{{OrganisationName}}
{{Order.OrganisationName}}

Posting the following:

POST http://api.aspose.com/v1.1/words/SalesQuote.docx/executeTemplate?cleanup=UnusedFields&appSID=(PRIVATE)&signature=(PRIVATE) HTTP/1.1
Content-Type: application/json
Host: api.aspose.com
Content-Length: 82
Expect: 100-continue
Connection: Keep-Alive

{"Order":{"OrganisationName":"ABC Company","SalesPerson":"Brian Dlan","blah":"!"}}

But when I download the resulitng file, it has simply converted my fields from moustache fields (eg {{Order.OrganisationName}}) into word-style merge fields (eg «Order.OrganisationName»)

Can someone please help me figure out what I’m doing wrong?

Brendan

Hi Brendan,
Can you please try posting data in XML format instead of JSON? You can use attached document and XML.
Best Regards,

Thanks Muhammad,

That seems to work fine.

Tell me, is it absolutely necessary to have the outer “foreach” statement? i.e. “{{#foreach Order}}”? Is there another mechanism by which we can assume the top-level node in the JSON/XML is the ‘base’ context and omit this top-level foreach?

Kind regards,

Brendan

Hi Brendan,
Yes, if you are using mustache fields in your template, you will have to use execute template feature and outer “foreach” statement is mandatory in that case. If your template does not contain any tables, you can go for simple mail merge in that case; please check https://docs.aspose.cloud/words/mail-merge/ for more details.
If your template contains tables as well as simple merge fields and you do not want to use outer “foreach” statement, you will need two API calls (i.e. execute mail merge with regions and without regions) in that case.
Please feel free to contact us in case you have further comments or questions.
Best Regards,

Is it possible to fix the bug which requires the outer #foreach statement?

It is unnecessary when there are not repeating blocks, and the proposed workaround (don’t use mustache templates) doesn’t take into account that the point of mustache templates is that they are easier for the end-user to work with than the Word merge fields.

Hi,
This is not actually a bug. This is a requirement depending upon the nature of this resource. We will discuss with the development team if this can be skipped and let you know.
Best Regards,

Hi Brendan,
A new feature request to remove outer foreach restriction has been logged into our issue tracking system as SAASWORDS-199. We will keep you updated on this issue in this thread.
Best Regards,

Thanks for being patient. We have good news for you i.e. SAASWORDS-199 have now been resolved. You may now please re-test your scenario with Aspose.Words for Cloud. Hope, this helps.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.