TinyButStrong - the PHP Template Engine
Categories > OpenTBS with DOCX >

Sub-Block Only Merging First Item in Array

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs

By: Luke
Date: 2017-03-01
Time: 05:03

Sub-Block Only Merging First Item in Array

I am trying to utilize a sub-block to display an address on multiple lines in a word document. However, when I merge the block, only the first item in the sub-block php array is displayed in the final document. That is, the array would look like this:

array(0=> 'line1', 1=>'line2', 2=>'city, state zip')

But, all that ends up in the final word doc is 'line1.'

My template looks like this:


[notice;block=begin;sub1=addressArray]

[notice.recipient]
[notice_sub1.val]

[notice;block=end]


I just can't seem to get anything but the first value to merge. Any help would be appreciated.
By: Skrol29
Date: 2017-03-02
Time: 22:31

Re: Sub-Block Only Merging First Item in Array

Hi Luke,

The block "notice_sub1" has no bounds defined (by parameter "block").
When no bound of block is defined, TBS merges only the first record.

Maybe you do not need sub-block.
The following should work:
[notice;block=begin]

[notice.recipient]
[notice.addressArray.0]
[notice.addressArray.1]
[notice.addressArray.2]

[notice;block=end]
By: Luke
Date: 2017-03-03
Time: 14:54

Re: Sub-Block Only Merging First Item in Array

Skrol29,

Thank you very much for your response. I appreciate your suggestion but the address array doesn't have a static number of elements. Addresses in this application vary from between 2 and 5 lines so the sub-block really seems like the best solution. After some more tinkering, I was able to solve my problem. I placed the tag inside a table like this:


[notice;block=begin;sub1=addressArray]

[notice.recipient]
[notice_sub1.val;block=tbs:row]

[notice;block=end]

Also note for those new to tbs like myself that, in the word template, the [notice_sub1.val;block=tbs:row] needs to be placed within a table row. If you don't do this, tbs will throw an error.

Once I made this change, all the records of the sub-block array were properly merged.