Categories > OpenTBS with DOCX >

Sub-blocks and table rows in Word templates

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Owen
Date: 2016-03-29
Time: 11:45

Sub-blocks and table rows in Word templates

Hi, I'm trying to merge a PHP multidimensional array with a DOCX template using sub-blocks, but have something wrong - every row in each of the nested arrays is creating a new instance of the table in the generated Word document instead of a new row. I've successfully generated table rows using the OpenTBS sample DOCX template as a guide, but there doesn't seem to be an example for nested arrays & sub-blocks.

My requirement is for MySQL queries to populate the arrays, so the number of rows in each table will always be variable, but to explain the problem I've created a simple static example of a nested array....

$mainBlock = array(
    0 => array(
        'description' => 'Sample Heading',
        'name'=>'John Smith',
        'items' => array(
            0 => array(
                'number'=>1,
                'detail'=>'Sample detail for number 1'
            ),
            1 => array(
                'number'=>2,
                'detail'=>'Sample detail for number 2'
            ),
        ),   
    ),               
);
$TBS->MergeBlock('a', $mainBlock);

My DOCX template is:

[a;block=begin;sub1=items]

Main Group: [a.description]
Name: [a.name]

[a_sub1;block=begin]
___________________________________________________
| Title           | Description                   |
___________________________________________________
| [a_sub1.number] | [a_sub1.detail;block=tbs:row] |
___________________________________________________

[a_sub1.items;block=end]
[a;block=end]

I've tried many variations to try and define the block correctly including having the block=begin/end inside the table, specifying block=tbs:table/row in the begin sub-block instruction etc., (in some cases I get table rows, but then the table headings are out of sync with the columns, and re-appear in the middle of the table etc.)... but I cannot get the data to output correctly to rows instead of whole tables.

Would really appreciate a working example that I can expand to several levels of nested arrays.

Thanks.