Mustache Template documentation

Hello Aspose,

Is there any documentation for how the Mustache template syntax has been implemented in Aspose.Words ?

I’m particular interested in the Mustache replacement of {IF mergefield}.

Regards, Paul

Hi Paul,

Thanks for your query. Unfortunately, the documentation of Mustache template syntax is not available at the moment. You can enable mail merging into plain text fields by enabling the MailMerge.UseNonMergeFields property and can freely mix them in your template with the Microsoft Word fields such as IF or Formula fields. Please check this blog post for your kind reference.

Please check the following code snippet your requirement. I have attached the input and output documents with this post.

Document doc = new Document(MyDir + "in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
String[] fieldNames = new String[]
{
    "name",
    "value",
    "text",
    "taxed_value"
};
Object[] fieldValues = new Object[]
{
    "Chris",
    10000,
    "True",
    10000 - (10000 * 0.4)
};
doc.MailMerge.UseNonMergeFields = true;
doc.MailMerge.Execute(fieldNames, fieldValues);
doc.UpdateFields();
doc.Save(MyDir + "AsposeOut.docx");

Please let us know if you have any more queries.

Hello Tahir,

Thanks for your reply.

Can you give an example where in the true result of an IF field a Mustache foreach is computed ?

e.g. Should it be possible to do something like the following (this causes an infinite loop in my testing):

{ IF {{PrintPreviousPhase}} = True “{{#foreach NotCompleted}}{{Name}}{{/foreach NotCompleted}}” * MERGEFORMAT }

Can you also clarify if you have implemented a Mustache like syntax or a Mustache template engine.

Regards, Paul.

Hi Paul,

Thanks for your query. Yes, you can use the following syntax of Mustache but there is an issue with Aspose.Words for .NET v 11.7.0. The Mail Merge with Regions freezes when used inside (IF MERGEFIELD) . I am checking this issue with our development team and will update you via this forum thread once I get response from our development team.

{ IF {{PrintPreviousPhase}} = True “{{#foreach NotCompleted}}{{Name}}{{/foreach NotCompleted}}” * MERGEFORMAT }

Hi Paul,

Further to my last reply, Please use the following code snippet with Mustache template. I have attached the input and output document with this post. You can use the following syntax of Mustache with Aspose.Words.
{ IF {{PrintPreviousPhase}} = True "{{#foreach NotCompleted}}{{Name}}{{/foreach NotCompleted}}" \* MERGEFORMAT }

DataSet ds = new DataSet();
ds.ReadXml(MyDir + "in.xml");
Document doc = new Document(MyDir + "in9.docx");
doc.MailMerge.UseNonMergeFields = true;
// Execute the nested mail merge with regions
doc.MailMerge.ExecuteWithRegions(ds);
String[] fieldNames = new String[]
{
    "PrintPreviousPhase"
};
Object[] fieldValues = new Object[]
{
    "True"
};
doc.MailMerge.Execute(fieldNames, fieldValues);
doc.Save(MyDir + "AsposeOut.docx");

Please let us know if you have any more queries.

Thanks a lot!!
GB

Hi Paul,

Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.