Comment Processors

Alongside expression replacement, Office-stamper presents the feature of processing comments associated with paragraphs in your .docx template. These comments act as directives for manipulating the template.

How Comment Processors Work

  1. You add a comment to a paragraph, table row, or other element in your Word document.
  2. In the comment, you write a special expression that tells Office-stamper what to do with that element.
  3. When Office-stamper processes the document, it finds these comments and applies the specified operations.
  4. After processing, the comments are removed from the final document

Default Comment Processors

Office-stamper comes with several built-in comment processors that handle common templating needs:

Table Resolution

The resolveTable processor allows you to dynamically generate a table from data:

resolveTable(report.dataTable)

Headers and Footers

The .docx file format doesn’t permit comments within headers or footers. But there’s a workaround in Office-stamper. If you want to display contents within headers or footers conditionally, or require repetitive elements:

  1. Craft the expression as you would in a comment.
  2. Encapsulate it with "#{}".
  3. Position it at the starting of the paragraph you intend to manipulate.

Example:

#{displayParagraphIf(showPageNumbers)} Page ${pageNumber} of ${totalPages}

Error Handling

By default, an exception is thrown if a comment fails to process. However, successfully processed comments are wiped from the document.

You can customize the error handling behavior. See the Troubleshooting section for more details.

Next Steps

Edit this page