By: Theo4016
Date: 2013-08-23
Time: 15:40
|
Conditionnal templating
Hi everybody :)
I have a very simple problem, but as I'm very new to TinyButStrong library, I have a lot of difficulties to solve it, that is why I ask your help.
I want to display a text, depending on a variable value (conditionnal displaying).
In my PHP code, I have a variable called $test, with value 0, and I want to display something depending on this value.
In PHP code :
$parameters['test'] = 0;
$tbs->getOpenTBS();
$tbs->LoadTemplate('my_template');
$tbs->mergeField('client', $parameters);
$copy->show('name');
And my template :
[if [client.test]=0;then 'no error';else 'error found']
But when I do that, the result is exactly the template, as if the condition was not taken in count.
Do you have any solution for this problem ?
Thank you very much.
|
By: Sarah Kemp
Date: 2013-08-23
Time: 16:54
|
Re: Conditionnal templating
I believe you need something to trigger the 'if'. Try:
[client.test;if [val]=0;then 'no error';else 'error found']
|
(Like the example in the manual)
If I remember right, 'val' should be replaced by the value of 'client.test'.
|
By: Theo4016
Date: 2013-08-23
Time: 17:14
|
Re: Conditionnal templating
Thank you for your answer, it helps me to progress. Now the condition triggers, but there is still a problem : the result of the test displays 'error found', but my client.test value is 0, as shown in the following PHP code :
$this->getOpenTBS();
$parameters = array('test' => 0);
$tbs->mergeField('client', $parameters);
|
So the test returns false. I aslo tried to define test with the string '0' but the result was the same.
Do you have any clue ?
Thank you very much.
|
By: Sarah Kemp
Date: 2013-08-23
Time: 17:17
|
Re: Conditionnal templating
I would suggest:
[client.test;if [val]=0;then 'no error';else [val]]
|
(Untested)
To verify that [val] is (or isn't) getting the value you want.
|
By: Theo4016
Date: 2013-08-23
Time: 17:33
|
Re: Conditionnal templating
Replacing [val] with [client.test], your code displayed me :
as if the variable was not interpreted...
|
By: Sarah Kemp
Date: 2013-08-23
Time: 17:44
|
Re: Conditionnal templating
What happens if you just merge 'client.test'?
|
By: Theo4016
Date: 2013-08-26
Time: 10:33
|
Re: Conditionnal templating
Hi,
In this case, it displays 0, so it correctly recognizes the variable. I really don't understand why it doesn't work...
|
By: Skrol29
Date: 2013-08-28
Time: 00:21
|
Re: Conditionnal templating
Hi Theo,
> Replacing [val] with [client.test], your code displayed me :
You should enter the Sarah's snippet "as is". [val] is a TBS keyword for expressions that refers to the current value.
Other whise, self-embedded fields may not works as you expects.
Search for "embedded TBS fields" in the manual.
|
By: Theo4016
Date: 2013-08-28
Time: 09:41
|
Re: Conditionnal templating
Hi,
Thank you for you answer, and for my misunderstanding ;)
Your solution works fine with .odt templates, but I can't manage to do the same thing with .docx templates. Is it a limitation of the templating engine or is it due to my computer ? (I use LibreOffice to make and edit templates).
|
By: Skrol29
Date: 2013-08-28
Time: 13:29
|
Re: Conditionnal templating
Hi,
It work the same with DOCX. But Ms Word often cut the text (and TBS fields) with internal formating information. You should copy the snippet of the TBS fields, and past "without formating" in order to clean it up. Then it should work.
|
By: Theo4016
Date: 2013-08-28
Time: 13:38
|
Re: Conditionnal templating
Yes, now it works perfectly. Thank you for your time and your help ! :)
|
|
Posting in progress.
Please wait...
|