We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

MoveToMergeField is ignored when using the Mustache syntax


I am converting our templates to use the "mustache" syntax.

I encountered a problem with the MoveToMergeField method.
Reading the following post we conclude that this method poses a problem if use in combination with mustaches.

"I have received response from our development team and like to share with you that "Moustache" fields have a limited support at the moment"

The GetFieldNames seems fixed in a later update of Word. But MoveToMergeField is still ignored

Can you confirm this please?

Is there a fix coming or do we need to emply a workaround?

Below is our code. It replace the string true/false with checkboxes

Regards, Tom

public class HandleMergeField : IFieldMergingCallback
private DocumentBuilder _mBuilder;

/// This handler is called for every mail merge field found in the document,
/// for every record found in the data source.
void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
if (_mBuilder == null)
_mBuilder = new DocumentBuilder(e.Document);

// We decided that we want all boolean values to be output as check box form fields.
if (e.FieldValue is String)
if ((string) e.FieldValue == "false" || (string) e.FieldValue == "true")
// Move the "cursor" to the current merge field.

// It is nice to give names to check boxes. Lets generate a name such as MyField21 or so.
string checkBoxName = string.Format("{0}{1}", e.FieldName, e.RecordIndex);

_mBuilder.InsertCheckBox(checkBoxName, (string) e.FieldValue != "false", 10);

I tried the latest 14 build and also 15.6.0

My conclusion is that these don't support MoveToMergeField in my scenario

The forum post that I refer above alludes to converting them to regulare merge fields? This can be a solution but how to do this in Aspose.Words?

Thanks, Tom

I got some more information about the issue

MoveToMergeField does not work here and the text is insert at position 0, beginning of the document

{{ #foreach X1 }}
{{ /foreach X1 }}

This works! MoveToMergeField goed to the expected position

{{ #foreach X1 }}{{ #foreach V1 }}
{{ /foreach V1}}{{ /foreach X1}}


So is the issue maybe related whether points are used in the addressing? V1.A vs A ?

Also, I was kind of expecting that the following also works {{X1.V1.A}} but it gives a runtime error. Isn't arbitrary nesting/points supported?


Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document containing template (mustache fields)
  • Aspose.Words generated output document which shows the undesired behavior
  • Your expected document which shows the correct output. Please create this document using Microsoft Word application.
  • Please create a standalone application (source code without compilation errors) that helps us reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip them and Click ‘Reply’ button that will bring you to the ‘reply page’ and there at the bottom you can include any attachments with that post by clicking the ‘Add/Update’ button.

Best regards,