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

扶醉桌前 提交于 2019-12-26 12:38:25

问题


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:


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);


来源:https://stackoverflow.com/questions/53510982/can-a-when-conditional-section-show-content-based-on-a-contains-or-includes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!