Categories > OpenTBS with DOCX >

Docx, subblocks, multidimensional array

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: lena
Date: 2016-12-02
Time: 10:42

Docx, subblocks, multidimensional array

Hi,

I am triyng to make such a table with DOCX templates, but can not understand how to do. I tried to make with subblocks,  but no result


    text       qty     unit    Price/unit    sum
    Type1
    Product1        2       pieces      100       200
                                                 Sum:200
    Type2                 
    Product2        4       pieces      350          1400
    Product3     5       pieces        15       75
                                               Sum:1475
                                        Total sum: 1675


My array is:

array(2) {
    [0]=> array(2) { ["type"]=> string(5) "type1"
                         ["sum"]=> string(3) "400"
             ["products"]=> array(1) {
                [0]=> array(6) { ["product"]=> string(8) "product1"
                         ["unit"]=> string(6) "pieces"
                                                 ["quantity"]=> string(1) "2"
                                                 ["price"]=> string(5) "20.00"
                                                 ["discount"]=> string(0) ""
                                                 ["sum"]=> string(5) "40.00" } } }
       [1]=> array(2) { ["type"]=> string(5) "type2"
            ["sum"]=> string(3) "500"
                        ["products"]=> array(2) {
                [0]=> array(6) {
                        ["product"]=> string(8) "product2"
                        ["unit"]=> string(6) "pieces"
                        ["quantity"]=> string(1) "4"
                        ["price"]=> string(6) "350.00"
                        ["discount"]=> string(0) ""
                        ["sum"]=> string(7) "1400.00" }
                [1]=> array(6) { ["product"]=> string(8) "product3"
                         ["unit"]=> string(6) "pieces"
                         ["quantity"]=> string(1) "5"
                         ["price"]=> string(5) "15.00"
                         ["discount"]=> string(0) ""
                         ["sum"]=> string(5) "75.00" } } } }

Could you  give me any tips?


I would like to make with subblocks, because this is more userfriendly.

I tried to make:

$TBS->MergeBlock('type','array','itemsBlock');
$TBS->MergeBlock('item','array','itemsBlock[%p1%][products]');

and in docx:

[type.type;block=tbs:row;]
[item.product;block= tbs:row;p1=[type.$]]       
       



By: Skrol29
Date: 2016-12-04
Time: 22:40

Re: Docx, subblocks, multidimensional array

Hello Lena,

With your data structure you can use Automatic sub-blocks.

script:
$TBS->MergeBlock('type', $data);

template:
[type.type;block=tbs:row+tbs+row;sub1=products] // define the main block on 2 rows
[type_sub1.product;block=tbs:row] // define the sub-block as the second row of the main block.
By: lena
Date: 2016-12-05
Time: 11:37

Re: Docx, subblocks, multidimensional array

Thank you very much for the answer, Skrol29)))

Automatic sub-blocks work, but i think that this is a little bit difficult for a user to understand what ist items_sub1 etc.

And if i would like to make with dynamic sub-blocks, is this something like this?? because this schema does not work too. Can i use dynamic subblocks in DOCX?:

$TBS->MergeBlock('type','array','itemsBlock');
$TBS->MergeBlock('item','array','itemsBlock[%p1%][products]');

Docx:
[type.type;block=tbs:row+tbs:row;]
[item.product;block=tbs:row;p1=[type.$]]   
   
By: Skrol29
Date: 2016-12-06
Time: 15:06

Re: Docx, subblocks, multidimensional array

Yes dynamic sub-blocks work with OpenTBS and DOCX.

Your snippet seems ok. What do you have not working ?