How to Add Comments in Aspose Template Syntax Without Affecting Output?

I am using Aspose’s templating engine to generate documents dynamically. I need a way to add comments within the template that:

  • Do not interfere with the template processing.
  • Are completely ignored and do not appear in the generated document.

Is there a built-in way to achieve this? If not, what is the recommended approach for adding comments within templates that remain hidden in the final output?

@abhishekouta

To add comments in Aspose’s template syntax without affecting the output, you can use the optional comment feature within the template tags. This allows you to include human-readable explanations that will be ignored by the engine during processing.

Here’s how you can structure your template syntax to include comments:

<<tag_name [expression] –switch1 –switch2 ... # optional_tag_header // your comment here >>

In this structure, the comment follows the // and will not appear in the generated document. This way, you can document your template without interfering with the processing or output of the document.

Additionally, if you want to ensure that any empty paragraphs created by the processing of these tags are removed, you can use the ReportBuildOptions.RemoveEmptyParagraphs option. This will help maintain a clean output by eliminating any unnecessary empty paragraphs that might result from the template processing.

By using this approach, you can effectively manage comments within your templates while ensuring they remain hidden in the final output.

I am still looking for actual practical suggestions from aspose team

@abhishekouta As it was mentioned above, you can insert comments into the tags like this:

<<tag_name [expression] –switch1 –switch2 ... # optional_tag_header // your comment here >>

Unfortunately, there is no other way to insert comments within LINQ Reporting Engine template syntax.

@alexey.noskov
I’m exploring if there’s a specific tag or syntax I can use to add comments in the following format:

<<which_tag_for_comment>>Below tag will print person’s name<</which_tag_for_comment >>
<<[person.name]>>

If such a syntax doesn’t currently exist:

  1. Is there a possibility to add this feature to the library itself?
  2. One workaround I’ve considered is using the <<if [false]>> tag, like this:
<<if [false]>>
Below tag will print person’s name
<</if>>

I’m thinking of replacing <<comment>> with <<if [false]>> and <</comment>> with <</if>> in the document.

Could this approach cause any issues until Aspose officially provides a comment tag?

@abhishekouta Why do not you simply use already supported syntax like this:

<<[“”] //This is comment and will be remove from the document after building the report.>>

Thanks @alexey.noskov ,
but this syntax may not fit for my requirement, because

<<[“”] //This is comment and will be remove from the document after building the report. However, end user might also comment tag itself like <<[person.name]>>, Which cause issue, this sentence will be printed in document>>

So in generated document, below will be printed.
, Which cause issue, this sentence will be printed in document>>

is there anyway to handle this as well?

thank you!

@abhishekouta

This is expected behavior, because the first entry of “>>” is considered as the end of a tag, so the rest of content is considered as plain text then. To handle this, an end user may use an escape character between two ‘>’ characters in a comment like this:

<<[“”] //This is comment and will be remove from the document after building the report. However, end user might also comment tag itself like <<[person.name]>\>, Which cause issue, this sentence will be printed in document>>

The escape character can be any character except ‘>’.

It’s working,
Thank you @ivan.lyagin for guidance.

1 Like