Categories > OpenTBS with ODT >

Repeating a Block

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: handbuch
Date: 2010-10-29
Time: 12:42

Repeating a Block

Hi,

I have an array: http://pastebin.com/NFGm7bqZ

I now Need a Documetn which looks like this: http://pastebin.com/PkxxrniB

I can fill up my Document with the firstentry (getränke) but i dont knwo how i can do the same again underneath that with the 2. entry (essen).

With [a;block=begin;] and end, i dont get it. Can someone give me an example?

By: Skrol29
Date: 2010-10-29
Time: 14:41

Re: Repeating a Block

If it is sure that you can have only 2 entries "Getränke" and "Essen" then you can simply put two tables in your templates, and merge them one by one:
$TBS->MergeBlock('a1', 'array', $data['Getränke']);
$TBS->MergeBlock('a2', 'array', $data['Essen']);

But if you may have other entries, or if you don't want to code the tables twice, then you can use sub-blocks.
Document (I assume it is ODT):
[a;block=begin]

    Drinks

    ---------------------------------------------------------------------------------------------
    |  [sub.Titel_DE;block=table:table-row;p1='[a.$;htmlconv=no]'  |  [sub.PriceSmall_CHF] $  |
    ---------------------------------------------------------------------------------------------

[a;block=end]

PHP:
$TBS->MergeBlock('a', 'array', $data); // Main block
$TBS->MergeBlock('sub', 'array', 'data[%p1%]'); // Sub block. $data must be a global variable to have this working

Parameter "htmlconv=no" is set in the template in order to prevent the key to be UTF-8 converted by TBS.

(edited at 15:45)
By: handbuch
Date: 2010-10-29
Time: 16:31

Re: Repeating a Block

Thanks. I want that block i hve for each entrie in my array. Yes it is odt. i'll try that, thanks.
By: handbuch
Date: 2010-11-01
Time: 16:03

Re: Repeating a Block

i dont get it. i cant get the into 2nd level. the first one it loops througth but the 3 makse problems. can you give a very simpel exsample? please

since it merges real time i cant make an foreach and loop througth. and i dont get that with that sub stuff. they always work with tr=p1 or soemthign and i have no html.

I have a array:

Array (
"Categorie0" = (
                        0 = array (
                                       "Titel" = "Something
                                       "Price" = 22.20
                                      )
                        1 = array (
                                       "Titel" = "Something
                                       "Price" = 22.20
                                      )
                       )
"Categorie1" = (
                        0 = array (
                                       "Titel" = "Something
                                       "Price" = 22.20
                                      )
                        1 = array (
                                       "Titel" = "Something
                                       "Price" = 22.20
                                      )
                       )
)

And now i want something liek this:

Block Start
      Categorie (This is the key value of the 1 lvl (Categorie1,Cateogir2)

           [x.Titel]
           [x.Price]

Block End


so and now i need a php script which loops that template. I get the block repeated with the categorie name. but the i dont know how i could do the sub level.

Please help :) What exsactly does the % at 'data[%p1%]'?


By: Skrol29
Date: 2010-11-01
Time: 22:05

Re: Repeating a Block

>i have no html

Indeed. But parameter "htmlconv" is badly named, in fact it means something like "strconv".

The sub stuff is supposed to make the loop on the second level for you.
But I suggest that you use the last version of TBS, its version 3.6.1. It bring a new feature that should help you on your template.

Template:
[a;block=begin;sub1]

    Drinks

    ---------------------------------------------------------------------------
    |  [a_sub1.Titel_DE;block=table:table-row]  |  [a_sub1.PriceSmall_CHF] $  |
    ---------------------------------------------------------------------------

[a;block=end]

PHP:
$TBS->MergeBlock('a', 'array', $data);

Parameter "sub1", defined in the main "a" block, indicate to TBS that there is a sub-block to merge. Because sub1 has no value, it means that data for the sub-block are directly saved in the item. Which is your case. (sub1 without value works only since TBS 3.6.1).
The TBS search for a sub-block to merge, and this sub-block is supposed to be called "a_sub1". That what is done ins the template.

Tell me if this one works better for you.
By: Anonymous
Date: 2010-11-02
Time: 09:23

Re: Repeating a Block

hi, my template:
[a;block=begin;sub1]




[a_sub1.Titel]

[a;block=end]

Code:
<?php
require_once 'tbs_class_php5.php';
require_once 'tbs_plugin_opentbs.php';

$TBS = new clsTinyButStrong;
$TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);

// Prepare some data for the demo
$card = Array
(
    "cat" => array (
                0 => Array
                        (
                            'Titel' => 'Merlolt'
                        ),
                1 => Array
                        (
                            'Titel' => 'xxx'
                        )
            ),
    "cat1" => array (
                0 => Array
                        (
                            'Titel' => 'aaaa'
                        ),
                1 => Array
                        (
                            'Titel' => 'bbbb'
                        )
            ),
);

$TBS->LoadTemplate('tmp.odt');

$TBS->MergeBlock('a', 'array', $card);


$TBS->Show(OPENTBS_DOWNLOAD+TBS_EXIT, 'rechnung.odt');
?>


thanks, but stilll how do i loop through that sub? it pritns me$card[cat][0] but not the 2nd. Always the first, sub1 doesnt loop. why? how can i make it looping?

thanks a lot
By: Skrol29
Date: 2010-11-02
Time: 11:16

Re: Repeating a Block

I guess only the first [a_sub1.Titel] item is merged.
This is because you haven't defined a block for the sub-section.
Replace
  [a_sub1.Titel]
with
  [a_sub1.Titel;block=something]

"something" must be an XML tag that can be duplicated for your merging, otherwise you can use the explicit syntax:

  [a_sub1;block=begin]
    [a_sub1.Titel]
  [a_sub1;block=end]
By: Anonymous
Date: 2010-11-02
Time: 16:12

Re: Repeating a Block

Got it. sry i didnt read you post carefully. So i have block=table blabla. I need now somethign for plan text. So, what should i then take? i will check the manual.
By: Skrol29
Date: 2010-11-02
Time: 16:53

Re: Repeating a Block

What do you mean by plan text?
Parameter "block=... " only defines the section that will be repeated. In this section you can put several TBS fields like [a_sub1.Titel], [a_sub1.PriceSmall] ,...
By: Anonymous
Date: 2010-11-03
Time: 08:18

Re: Repeating a Block

i got it. thansk a lot! but i still have a little question. how can i make my variables not interpretable? like. xxx;block=begin makes an space in my template, how can i make tbs doesnt do that? and can i somehow smaller the variables? so [a_sub1.Titel_DE] get into $x or something?
By: Skrol29
Date: 2010-11-03
Time: 17:36

Re: Repeating a Block

> [xxx;block=begin] makes an space in my template

It shouldn't be. Nevertheless, you can put the field into a tag of your choice, and then add parameter "comm=tag" in your field. Then TBS will extend the bounds of to fields upon the bounds of the tag.
I don't know what to suggest for embedding tag in OpenOffice.

> can i somehow smaller the variables? so [a_sub1.Titel_DE] get into $x or something?

You can make your own translation before the merging.
For example:
$TBS->Source = str_replace('[x]', '[a_sub1.Titel_DE]', $TBS->Source);
 
By: Anonymous
Date: 2010-11-04
Time: 08:35

Re: Repeating a Block

I didnt 100% understand what you meant with the tags, but it works like i had it and it doesnt rly annoy me so, dont care. The stuff with the translation looks great! Thanks a lot! You helped me a lot, thank you :)
By: Skrol29
Date: 2010-11-04
Time: 09:56

Re: Repeating a Block

Hi,

Here is an examples of what I mean:

You can insert comment in your ODT template, and then add insode the comment the following TBS fields:
[a_sub1;block=begin;comm=office:annotation]
Since the ODT comment is a <office:annotation> tag, then the TBS field will take the place of the comment.

It also works with paragraphs:
[a_sub1;block=begin;comm=text:p]
Here the TBS field will take the place a the paragraph it is embedded in.