docx-mailmerge icon indicating copy to clipboard operation
docx-mailmerge copied to clipboard

Mergefield does not work with if statement

Open chlab opened this issue 7 years ago • 1 comments

Expected Behavior

I am trying to use a merge field in an if condition. Ideally, the condition would be evaluated during the mail merge(?). This would make mailmerge templates much more flexible.

My intended use-case is to check a checkbox depending on a placeholder value.

Note: if there is another way to do this (check a checkbox) please let me know!

Current Behavior

The if expression is not evaluated.

Steps to Reproduce

Add a merge field and wrap it in an if condition:

{ IF { MERGEFIELD toggle_test } = "True" "Yes" "No" }

Merge the template as follows:

from mailmerge import MailMerge

with MailMerge('merge_template.docx') as document:
    document.merge(
        toggle='True'
    )

    document.write('merge_output.docx')

Your Environment

  • Python version: 3.4.2
  • docx-mailmerge version: 0.4.0
  • Word for Mac Version 16

chlab avatar Jun 12 '18 12:06 chlab

Unsure if I am correct or not.

It seems "toggle='True'" should be written as "toggle_test='True'".

faiyeah avatar Oct 25 '18 03:10 faiyeah