5

I'm kinda new with TinyButStrong, and I would like to know how I can check if a boolean variable is 0 or 1 ? For example, I have this:

$TBS->MergeBlock('tests', $tests);

And $tests have a variable call 'activated' which is a boolean. So, in my .docx document, I would like to write the string 'Activated' if the variable is set to true(1), and 'non-activated' if it set to false(0).

Which syntax should I use in the .docx document ?

Thanks in advance.

shim
  • 9,289
  • 12
  • 69
  • 108
NH3
  • 189
  • 2
  • 12
  • `isset($var) or empty($var)` if possible – Rafee Dec 20 '12 at 09:14
  • 1
    Hello, my problem is that I would write the "isset" or "empty" inside my .docx template, something like: [isset(tests.actived)]Activated, I don't want to check in my php script. – NH3 Dec 20 '12 at 09:27

1 Answers1

6

They are several ways to format values during the merging, but by default TBS converts data items into strings using the PHP implicit conversion.

Thus, true is converted into '1' and false is converted into '' (empty string).

For the non-existing value: If the key in the array you want to merge does not exist, then you can avoid the TBS error message using parameter noerr, and the value for replacement is '' (empty string).

So your solution is :

[test.ativated;noerr;if [val]=1;then 'Activated';else 'non-activated']
Skrol29
  • 5,402
  • 1
  • 20
  • 25