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

Free Support Forum - aspose.com

Aspose.Words for Java 15.6 - WORDSNET-11812 Add feature to use the IF (Mustache syntax) with mail merge

Hi, could you please provide me an example of how using this new feature (IF with mustache syntax) ?
Thanks

Simone

Hi Simone,
Thanks for your inquiry. Please check the following code example for your kind reference. Hope this helps you. Please let us know if you have any more queries.

Document doc = new Document(); 
DocumentBuilder builder = new
DocumentBuilder(doc);    
builder.writeln("<<foreach [item in items]>><<if [indexOf() % 2==0]>><<[item]>>" );
builder.write("<<else>>");
builder.getFont().setBold(true);
builder.writeln("<<[item]>>");
builder.getFont().setBold(false);
builder.write("<</if>><</foreach>>");
ReportingEngine engine = new ReportingEngine();
java.util.List<String> items = new ArrayList<String>();    
items.add("Item1");
items.add("Item2");
items.add("Item3");
engine.buildReport(doc, items, "items");
doc.save(MyDir + "Out.docx");

Sorry, but it’s not mail merge format as stated in WORDSNET-11812. It’s linq engine.
I’ve undertood that you add “if” statement to mustache format, something like {{#if…}}
Am i missing something ?

thanks

Simone

Hi Simone,

Thanks for your inquiry. This issue WORDSNET-11812 has been closed. You can achieve your requirement using new linq reporting engine. We have introduced a new LINQ Reporting Engine
which is a part of the Aspose.Words API that enables you to build
reports using an extended set of reporting features. The engine enables
you to reference business objects of your application in report
templates directly, which agrees well with Domain-Driven Design
widely used in modern software development. Moreover, the engine uses a
subset of C# language in its template syntax. These features enable you
as a developer to compose report templates in a familiar and intuitive
way.

Please read following documentation links for your kind reference.
https://docs.aspose.com/words/java/template-syntax/
http://www.aspose.com/docs/display/wordsjava/Using+Conditional+Blocks

Is it possibile to add if statement the same way in Mail Merge with mustachhe format ?`

<<# if [condition]>>
<<# else>>
<</if>>

Hi Simone,

Thanks for your inquiry. No, the template syntax of If and mail merge fields is different in classical mail merge engine and new reporting engine.

A typical template for LINQ Reporting Engine is composed of common document contents and tags that
describe the template’s structure and data bindings. Please read the detail from here:
https://docs.aspose.com/words/java/template-syntax/

Could you add this feature (if statement) in classical mail merge with mustache format ?

thanks

Simone

Hi Simone,

Thanks for your inquiry. The requested feature was already logged as WORDSNET-11812. This issue has been closed because we introduced a new LINQ Reporting Engine which fulfill the IF statement requirements. So, please use new reporting engine and let us know if you face any issue.