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 text. <block switch="main.question.private"> But this is only appears if the block is switches on.</block> The normal text continues here.

If main.question.private has gotten a value in the model, everything will be output and the text will be:

This is text. But this is only appears if the block is switches on. The normal text continues here.

If main.question.private has not gotten any value, the part inside the <block> will not appear and the resulting text will be:

This is text. The normal text continues here.

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

You can also use all kinds of logical operators (such as AND and OR) in your blockswitch. These can be used to compare, add and refine your condition just like in the Studio.

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

For example, consider this blockswitch:

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

The block will only be appear if the value of private is greater than one and smaller than four. The X here represents the value of “main.question.private”.