Remove extra foreach wrapping in Mustache Templates using Aspose.Words REST API

Using the current version of the Aspose Cloud API executeTemplate call, it seems to be strangely necessary to wrap any variables to be substituted into the template with an outer object, and then “loop” over this outer object to get at them.


In our application, we need end-users to create the document templates. And every single end-user we try to teach the process to asks why the in the world you need to put the foreach before and after non-repeating sections; and I don’t think there is a good answer for it.

It means that if your document actually does have repeating stuff, that stuff is unnecessarily nested an extra level deeper than it really needs to be.

Could you please fix the API code so that it doesn’t require this unnecessary wrapping?

Example:

Given the following JSON context data:

{“name”:“Test Template Context String”}

that I actually want to get into a document (like so):

Hello, {{name}}.

The API is unable to process this unless you first wrap the payload data in an unnecessary outer context, e.g.:

{"obfuscatingWrapper":[{"name":"Test Template Context String"}]}

and then peel off that same wrapper in the document with a #foreach loop, as so:

{{#foreach obfuscatingWrapper}}Hello, {{name}}.{{/foreach obfuscatingWrapper}}


Hi,

Foreach is not required for all repeating structure or nested structures but one foreach is required to wrap all fields in the document. Let say if you have a repeating foreach section in the document and all of the mustache fields are inside that foreach, you do not need to wrap it inside an extra foreach.

If you have a mixture of not-repeating and repeating fields inside a document, then you need to wrap all the fields inside one main foreach. It does not take a lot of effort from customer's point of view but makes things consistent at our end.

We will further discuss with the development team and let you know if it is feasible to lift this requirement of wrapping all fields inside a main repeating foreach.

Sorry for the inconvenience.

Best Regards,

Hi,

A new feature request to remove restriction to have outer foreach structure in the templates 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.
(1)

@erik88

As an update, please note since Aspose.Words Cloud 19.4, we have joined “ExecuteMailMerge” and “ExecuteTemplate” methods. Now Aspose.Words Cloud API has a single “ExcecuteMailMerge” method that can be used with both template types i.e. mailmerge fields and mustache. Please feel free to contact us for any assistance.