TinyButStrong - the PHP Template Engine
Categories > TinyButStrong general >

How to properly display/hide some data in a .docx by checking the var content

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs

By: Cozen
Date: 2015-12-22
Time: 15:46

How to properly display/hide some data in a .docx by checking the var content

I just want to know how to achieve that properly:

In a .docx,
If I have a variable for exemple a boolean one,
I need to hide a block of content if it's true (or 1) and hide the other one and do the same reverse thing if it's 0.
As far as I can see, the best way to do that is the creation of block however I can't make it works..

Exemple:
[table_4_0.0_block;block=begin]
    [table_4_0.0_block.field_25.0.field_0;when [val]==1]
    Block1
[table_4_0.0_block;block=end]
[table_4_0.0_block;block=begin]
    [table_4_0.0_block.field_25.0.field_0;when [val]==0]
    Block2
[table_4_0.0_block;block=end]
The result is :
Block1
Block2

Thank you for the help and I wish you happy holidays.
By: Cozen
Date: 2015-12-23
Time: 12:02

Re: How to properly display/hide some data in a .docx by checking the var content

I can make an if statement like that :
[table_4_0.0.field_25.0.field_0;if [val]=1;then ‘hello [table_4_0.0.field_26] !’;else '.....']
It will works but a second problem is pointing: [table_4_0.0.field_26] is display like a string..
I saw some thread about it with [onshow;...] attribute nevertheless it didn't work at all for me..
By: Skrol29
Date: 2015-12-28
Time: 09:02

Re: How to properly display/hide some data in a .docx by checking the var content

Hi Cozen,

Your first snippet is not correct because parameter "when" is only for block definition, that is the TBS tag that has the paremeter "block=..."
So it should be:
[table_4_0.0_block;block=begin;when [table_4_0.0.field_25.0.field_0]==1]
    Block1
[table_4_0.0_block;block=end]
[table_4_0.0_block;block=begin;when [table_4_0.0.field_25.0.field_0]==0]
    Block2
[table_4_0.0_block;block=end]

By the way, in DOCX and ODT template, I recommend to not use "block=begin" / "block=end" because that may split an XML entity.
It is better to bound the block on visible entity like "block=tbs:p".
In your case it could be:
[table_4_0.0_block;block=2*tbs:p+;when [table_4_0.0.field_25.0.field_0]==1]
Block1
[table_4_0.0_block;block=2*tbs:p;when [table_4_0.0.field_25.0.field_0]==0]
Block2

The other snippet with parameter if/then/else doesn't work because embedded TBS fields works only under special circumstances.
See: http://tinybutstrong.com/manual.php#html_field

You may try something else with parameter "magnet=..." and "ope=minv".
By: Cozen
Date: 2016-01-07
Time: 10:03

Re: How to properly display/hide some data in a .docx by checking the var content

Hi Skrol, thanks for the help.
I tried these two snippets however any were working.
It always print me Block1 AND Block2...
I tried so many syntaxes like : =1; ==1; ="1"; ='1'; etc...
If I change the name of the block (table_4_0.0_block), the .docx print me all the snippet, so I'm sure that the name is correct.
The field is correct too (table_4_0.0.field_25.0.field_0).
I can't figure out where is the problem for now...
By: Cozen
Date: 2016-01-07
Time: 12:07

Re: How to properly display/hide some data in a .docx by checking the var content

EDIT:
I solved my problem by using an if statement for the static text and attribute magnet to variable text.
I can say it : it's fucking ugly and disgusting but it works.
It takes some much time if you have a lot of text but at least it works !
By: Skrol29
Date: 2016-01-08
Time: 00:01

Re: How to properly display/hide some data in a .docx by checking the var content

Ok.

I would be interested to have a look at your template, if it is permitted, in order to understand the difficulty.
By: Cozen
Date: 2016-01-08
Time: 11:00

Re: How to properly display/hide some data in a .docx by checking the var content

All the variables are added into a global array.
However each variable can be itself an array (so array of array (max 8 levels)).
Exemple :
Array
(
    [name] => table_4_0
    [value] => Array
        (
            [0] => Array
                (
                    [0] => Array
                        (
                            [name] => field_1
                            [value] =>
                            [type] => text
                        )
After that I can call the variables like this :
Var1 [table_4_0.0.field_0.0.field_0]
Var2 [table_4_0.0.field_0.0.field_1]
By: Cozen
Date: 2016-01-21
Time: 10:33

Re: How to properly display/hide some data in a .docx by checking the var content

Hi,
My problem still persist ='(

[table_4_0.0_block;block=begin;when [table_4_0.0.field_25.0.field_0]==1]
    Block1 = 1
[table_4_0.0_block;block=end]
[table_4_0.0_block;block=begin;when [table_4_0.0.field_25.0.field_0]==0]
    Block1 = 0
[table_4_0.0_block;block=end]

This snippet print me :
Block1 = 1
Block1 = 0

If I rename 'table_4_0.0_block' into any other name, the snippet will be broken (print me the code).
Thanks for the help.