Iteration of a variable to create two tables

49 views Asked by At

I have a variable with several values, I would like to iterate over the variable and create two distinct tables, one at the beginning of the document and another at the end.

However, when I replicate the table iteration code, only one is created. Is it possible to create two tables from the same variable?

.docx file text:

Some document start....

[onshow;block=begin;when [var1.total!=0]

| Name                      | Barcode          |
| ------------------------- | ---------------- |
| [var1.name;block=tbs:row] | [var1.barcode]   |

[onshow;block=end]


Some document middle....


[onshow;block=begin;when [var1.total!=0]

| Name                      | Barcode          |
| ------------------------- | ---------------- |
| [var1.name;block=tbs:row] | [var1.barcode]   |

[onshow;block=end]

Some end of document....

I tried to separate the tables into different paragraphs, but without success.

1

There are 1 answers

0
haruk1515 On

Yes it is possible to use the same variable on to separete tables.

I will add an example, let's say that in your code you have this array:

$data = array(
    array('name' => 'First Name', 'barcode' => '03430242',),
    array('name' => 'Second Names', 'barcode' =>  '213123',),
    array('name' => 'Third Name', 'barcode'  => '8797567654',)
    );

$TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);

$TBS->LoadTemplate('your_template');

and all the basic to make it work

Now, for sure you are using MergeBlock,something like:

$TBS->MergeBlock('a', $data);

and like that you can use it in the table:

Name Barcode
[a.name;block=tbs:row] [a.barcode]

oke, so what you need to do is add another MergeBlock

$TBS->MergeBlock('b', $data);

but now the first parameter of MergeBlock it will be 'b' not 'a' (it's like a new instance however it uses $data too, the same array 'a' is using)

Final result:

$TBS->MergeBlock('a', $data);
$TBS->MergeBlock('b', $data);



Some document start....

[onshow;block=begin;when [var1.total!=0]
Name Barcode
[a.name;block=tbs:row] [a.barcode]
[onshow;block=end]


Some document middle....


[onshow;block=begin;when [var1.total!=0]
Name Barcode
[b.name;block=tbs:row] [b.barcode]
[onshow;block=end]

Some end of document....

If you have any question just ask!