Using block switches in a document

Normally, a model creates text fragments which are exported to the document. But sometimes there is a part of a document you want deleted. You can use the block switch to get just that.

A block starts with <block switch="variablename"> and ends with </block>. A block switch is added to the document like this:

This is public.<block switch="main.question.private"> But this is private text.</block> And furthermore...

If main.question.private has gotten a value in the case up until the document creation, everything will be output and the text will be:

This is public. But this is private text. And furthermore...

If main.question.private has not gotten any value in the case up until the document creation, the part inside the block will not render and the resulting text will be:

This is public. And furthermore...

NOTE For the basic case sketched above, it is irrelevant what the value is, as long as it has gotten a value up until the document creation. It may have gotten this value either by being a question that was asked or by being the name of a formula that was evaluated. This means maybe contrary to your expectations, ‘falsy’ values (such as zero (0) or empty text) will still cause the contents to render.

Refining the switch

If you need a finer switch, use one of the two other allowed fields:

  • value: value that the variable must (not) be equal to, or
  • condition: a condition the value has to meet

Value: compares the value of the switch variable

<block switch="main.question.private" value="1">

Now, the block will only be output if the value of private equals 1. The double quotes are important here.

<block switch="main.question.private" value="!1">

Now, the block will only be output if the value of private does not equal 1.

Condition: adding more logic

In the condition field X acts as a placeholder for the the value of the switch (in this example: the value of main.question.private in the case). You can use that X in a boolean expression. As with the value field, the double quotes around the condition may not be left out.

<block switch="main.question.private" condition="X>1 AND X<4">

Now, the block will only be output if the value of private is greater than one and smaller than four.

The following operators are allowed in the condition field:

  • AND both a and b are true
  • OR a or b is true
  • = a equals b
  • > a is greater than b
  • < a is smaller than b
  • >= a is greater or equal than b
  • <= a is smaller or equal than b
  • <> a differs from b