Search code examples
opentbstinybutstrong

Can I use a flat data source for DOCX file with grouping or subblocks?


I'm wanting to merge into a DOCX file. I've got a flat list of groups and participants, like this (but with more data elements):

$my_data=array(
  array('group'=>'Monday','name'=>'John Smith'),
  array('group'=>'Monday','name'=>'Lea Bitto'),
  array('group'=>'Monday','name'=>'Frank Regardi'),
  array('group'=>'Tuesday','name'=>'Bob Forehead'),
  array('group'=>'Tuesday','name'=>'Sue Compton'),
  array('group'=>'Tuesday','name'=>'Fran Gerzi'),
)

I'd like to merge this into a template that would result in:

Group Info
Group Name

Table:
Table header row
Table data row(s) merging participants for this group
(end table)
(Page break)
Next group...

I tried experimenting with both subblocks and headergrp, but couldn't make this work. Is it possible to do this? And if so, how? Thanks!


Solution

  • The parentgrp is done for that.

    here is an example for doing what you're asking:

    Template :

    Here a paragraph having the property « page break before »
    [c;block=tbs:page;parentgrp=group]
    Group: [c.group]
    ----------------------------
    |            Name          |
    ----------------------------
    |  [c.name;block=tbs:row]  |
    ----------------------------
    

    PHP script:

    $TBS->MergeBlock('c', $my_data);