Docassemble: Templating Word documents in Docassemble (Part II, Conditional Paragraphs)

Using Jinja and Mako to set up conditional paragraphs in Docassemble Word documents.

In our last post, we taught you how to how to set up simple variables and conditional phrases using the Jinja and Mako syntaxes used in Docassemble. In this article, we'll teach you how to format Docassemble templates with conditional paragraphs.

Setting Up Conditional Paragraphs

If you have a conditional paragraph (as opposed to a conditional word or sentence within a permanent paragraph), you will need to format the if/endif statements slightly differently so that the system knows to remove the entire paragraph and the spaces before and after it.

The syntax is as follows:

{%p if VariableNameHere %}

Paragraph text here.

{%p endif %}

Conditional Numbered Paragraphs or Table Rows

This formatting can be used with numbered paragraphs or tables, too, by entering your "if" and "endif" phrases on separate lines before and after the numbered paragraph (or the desired table row), like this:

  1. {%p if VariableNameHere %}
  2. Paragraph text here.
  3. {%p endif %}

So, everything above stays constant except for the variable name.  This article assumes your question is a Yes/No question.  For formatting multiple choice or checkbox questions, reference Part I of this series below

Documate makes it easy to create Docassemble interviews without using any code.  Documate's Word add-in is also available in the Microsoft app store for Docassemble templating of conditional paragraphs, which eliminates the need to use Jinja syntax on Documate.

If you haven't already, check out the rest of our Docassemble resources:

Resources for Docassemble Developers

Jinja Guide Part I: Simple variables and conditional phrases

Jinja Guide Part II: Conditional paragraphs

Jinja Guide Part III: Performing calculations

Jinja Guide Part IV: Numerical calculations

Jinja Guide Part V: Formatting words

Documate Newsletter

Sign up for our newsletter to get product updates, exclusive client interviews, and more.

Start a free trial, or
chat with our team today:

By clicking “Accept”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. View our Privacy Policy for more information.