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

Array to table in dynamic page.

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

By: Keidari
Date: 2014-02-12
Time: 12:54

Array to table in dynamic page.

Hi

I have an array of associative arrays and I need to create table from these arrays to the dynamically created docx page. In example demo_ms_word.php it is show how image and some other information is added to these dynamic pages but how about table with different values in each page? Could you please show me an example how it is done.
By: Skrol29
Date: 2014-02-12
Time: 14:56

Re: Array to table in dynamic page.



For each record, if you need to merge only single data item of the record, then it only needs one TBS field per data item. Just like [b. name] in the example.

If you need to merge sub-data of the record, such as an array of sub-items to merge with table rows in the page, then you have to use the TBS sub-blocks. See the TBS manual for sub-blocks, it works exactly the same with OpenTBS.
By: Keidari
Date: 2014-02-13
Time: 10:56

Re: Array to table in dynamic page.

Hi.

Below is the structure of the array that I have. Title and text are other blocks in the dynamic page which works fine, but still I can't get that table to work.

Array
(
    [0] => Array
        (
            [tabledata] => Array
                (
                    [0] => Array
                        (
                            [name] => string
                            [param] => string
                            [value] => string
                        )
                    [1] => Array
                        (
                            [name] => string
                            [param] => string
                            [value] => string
                        )
                    [2] => Array
                        (
                            [name] => string
                            [param] => string
                            [value] => string
                        )
                )
            [title] => some string
            [text] => some string
        )
    [1] => Array
        (
            [tabledata] => Array
                (
                    [0] => Array
                        (
                            [name] => string
                            [param] => string
                            [value] => string
                        )

                    [1] => Array
                        (
                            [name] => string
                            [param] => string
                            [value] => string
                        )
                )
            [title] => some string
            [text] => some string
        )
)

In the template I have tried following:
[test.tabledata;block=tbs:row] which logically display value Array.

Second one was:
[test;sub1=tabledata]
[test_sub1.name;block=tbs:row]
This shows Array from the first row and second row is displayed as it is.

So what I'm missing here? It can't be anything big right?

Thanks.
By: FeRan
Date: 2014-03-27
Time: 18:21

Re: Array to table in dynamic page.

I have solved this problem.

on PHP side:
$TBS->MergeBlock('a', $data); // data - array similar as you

on DOCX
[a.fio;block=tbs:page;sub1=course]
bla-bla-bla and table-data:

[a_sub1.#] | [a_sub1.name;block=tbs:row] | [a_sub1.hour] | [a_sub1.result]
By: Skrol29
Date: 2014-03-27
Time: 23:38

Re: Array to table in dynamic page.


Thank you for sharing this.
By: Bruno Mannina
Date: 2017-04-25
Time: 10:27

Re: Array to table in dynamic page.

Hi FeRan, Skrol29, keidari,

I have exactly the same problem of you.
First line write Array and second line is displayed as it is. :(

The solution presented by FeRan don't solve my problem,

Do you have a solution ?

Thanks a lot for your answer,

Sincerely,
Bruno