Search code examples
phpopentbstinybutstrong

Is it possible to use a subblock on a subblock when creating docx with opentbs?


I am trying to output an array to docx file with opentbs plugin. My array has a nested array so im using a block for the main array with a subblock for the nested array. This works perfectly. My problem is the nested array also has a nested array of its own. Is it possible to output this with a sub-subblock?

Below is what i'm using in the docx template, the shipment data(block) and the entries data(subblock) is displayed how i need. For each entry i need the packs(sub-subblock) to be displayed but at the moment it just outputs the tags and not the packs data. Where am i going wrong?

[a.shipment_#; block=tbs:row;sub1=entries]  
   [a_sub1.id]  
   [a_sub1.shipping_name;block=tbs:row;sub2=packs] 
   [a_sub1.total_quantity]  
        [a_sub2.display_line;block=tbs:row]
[a_shipment_total]

This is the array:

Array
(
    [0] =>; Array
        (
            [entries] =>; Array
                (
                    [1] =>; Array
                        (
                            [id] =>; 10000
                            [shipping_name] =>; Name1
                            [total_quantity] =>; 135                           
                            [packs] =>; Array
                                (
                                    [0] =>; Array
                                        (
                                            [display_line] =>; 6 Steel Drums x 10L
                                        )

                                    [1] =>; Array
                                        (
                                            [display_line] =>; 5 Steel Drums x 15L
                                        )

                                )

                        )

                    [2] =>; Array
                        (
                            [id] =>; 100001
                            [shipping_name] =>; Name2 
                            [total_quantity] =>; 50                           
                            [packs] =>; Array
                                (
                                    [0] =>; Array
                                        (
                                            [display_line] =>; 2 Plastic Jerry Cans x 25L
                                        )

                                )

                        )

                    [3] =>; Array
                        (
                            [id] =>; 10002
                            [shipping_name] =>; Name3
                            [total_quantity] =>; 170                          
                            [packs] =>; Array
                                (
                                    [0] =>; Array
                                        (
                                            [display_line] =>; 1 Plastic Jerry Can x 20L
                                        )

                                    [1] =>; Array
                                        (
                                            [display_line] =>; 6 Plastic Jerry Cans x 25L
                                        )

                                )

                        )                    

                )

            [shipment_id] =>; #1234
            [shipment_total] =>; 355
        )

)

Solution

  • The sub-block feature does supports sub-sub-block.

    Block a_sub1 is the sub-block for block a.

    Block a_sub1_sub1 is the sub-block for block a_sub1, thus it is the sub-sub-block of 'a'.

    Here is how you template could be :

    [a.shipment_id;block=tbs:row;sub1=entries]  
       [a_sub1.id]  
       [a_sub1.shipping_name;block=tbs:row;sub1=packs] 
       [a_sub1.total_quantity]  
            [a_sub1_sub1.display_line;block=tbs:row]
    [a.shipment_total]