Can a 'when' conditional section show content based on a 'contains' or 'includes' parameter?

133 Views Asked by At

I'm using TBS/OpenTBS (thanks Skrol, it's awesome) to produce Word documents based on form inputs. One of the form fields is a checkbox. Let's say it has ten options. I can display content fine if a single option is selected, but if, say, 4 options are selected, I need to define a condition in my template for what happens if those precise 4 options are selected. I would have to do the same for every other permutation.

What I'm trying to do is use a 'when'-based conditional section so that it behaves as if it has a 'contains' or 'includes' parameter, but I don't know if that's possible. I want to be able to take this approach in the template:

  • If Option A is ticked (regardless of whether any others are ticked), output this
  • If Option B is ticked (regardless of whether any others are ticked), output that
  • If Option C is ticked (regardless of whether any others are ticked), output something else
  • Etc for the remaining options
  • If none are ticked, output nothing

Given that there could be large number of permutations, I don't want to have to define a condition for every single permutation. I just want the template to output a particular paragraph if an option ticked, regardless of whether others are ticked, and this would apply for every option.

Hope that makes sense. Does anyone know if TBS can do this please? Many thanks.

1

There are 1 best solutions below

0
On

Parameter magnet + ope=mok is done for that kind of purpose.

Using ope=mok:1, the TBS field will keep the magnet target if the value of the field is 1, and delete the magnet target in other cases. The TBS field is never displayed with ope=mok.

And if you use parameter noerr, then there will be no error displayed if the sub-item is not found. This can happen with HTML check-box controls: they simply return nothing when unchecked.

Example of template : (each ine is a paragraph)

[f_data.OptionA;noerr;ope=mok:1;magnet=tbs:p] output this
[f_data.OptionB;noerr;ope=mok:1;magnet=tbs:p] output that
[f_data.OptionC;noerr;ope=mok:1;magnet=tbs:p] output something else

PHP corresponding snippet:

$form_data = ...;
$TBS->MergeField('f_data', $form_data);