Categories > OpenTBS with DOCX >

Unwanted line breaks

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

Unwanted line breaks

I am merging an array block that contains a number of nested sub-blocks to create a competition results doc, and while the data is populating the Word document perfectly I'm getting unwanted line-breaks depending on which sub-blocks exist in each section of the array. Apart from the block headings that start on new pages, the only line-breaks in the template are between the end of each category sub-block and the table that displays results information for that sub-block.

Single line-breaks are fine, but I'm getting 3 blank lines in some places.  Is it possible to suppress extra line-breaks?

Here is my template...

[regionBlock;block=begin;sub1=sectionBlock;sub2=sectionResults]Region: [regionBlock.#] - [regionBlock.region_name;noerr]
Judges: [regionBlock.group_judge_name;noerr][regionBlock_sub1;block=begin;sub1=(category1);sub2=(results1);sub3=(category2);sub4=(results2);sub5=(category3);sub6=(results3);sub7=(category4);sub8=(results4)]
Section: [regionBlock_sub1.section_name;noerr][regionBlock_sub1_sub1;block=begin;sub1=entryBlock]
Category:  [regionBlock_sub1_sub1.category_id;]  - [regionBlock_sub1_sub1.category_name]
---------------------------------------------------------------------------------------------------
|[regionBlock_sub1_sub1_sub1.entry_number;block=tbs:row]|[regionBlock_sub1_sub1_sub1.entry_detail]|
---------------------------------------------------------------------------------------------------
[regionBlock_sub1_sub1.category1;block=end]
------------------------------------------------------------------------------------------------------------------------------
|[regionBlock_sub1_sub2.results_txt1;block=tbs:row]|[regionBlock_sub1_sub2.results_txt2]|[regionBlock_sub1_sub2.results_txt3]|
------------------------------------------------------------------------------------------------------------------------------
[regionBlock_sub1_sub3;block=begin;sub1=entryBlock]Class:  [regionBlock_sub1_sub3.category_id;]  - [regionBlock_sub1_sub3.category_name]
---------------------------------------------------------------------------------------------------
|[regionBlock_sub1_sub3_sub1.entry_number;block=tbs:row]|[regionBlock_sub1_sub3_sub1.entry_detail]|
---------------------------------------------------------------------------------------------------
[regionBlock_sub1_sub3.category2;block=end]
------------------------------------------------------------------------------------------------------------------------------
|[regionBlock_sub1_sub4.results_txt1;block=tbs:row]|[regionBlock_sub1_sub4.results_txt2]|[regionBlock_sub1_sub4.results_txt3]|
------------------------------------------------------------------------------------------------------------------------------
[regionBlock_sub1_sub5;block=begin;sub1=entryBlock]Class: [regionBlock_sub1_sub5.category_id;]  - [regionBlock_sub1_sub5.category_name]
---------------------------------------------------------------------------------------------------
|[regionBlock_sub1_sub5_sub1.entry_number;block=tbs:row]|[regionBlock_sub1_sub5_sub1.entry_detail]|
---------------------------------------------------------------------------------------------------
[regionBlock_sub1_sub5.category3;block=end]
------------------------------------------------------------------------------------------------------------------------------
|[regionBlock_sub1_sub6.results_txt1;block=tbs:row]|[regionBlock_sub1_sub6.results_txt2]|[regionBlock_sub1_sub6.results_txt3]|
------------------------------------------------------------------------------------------------------------------------------
[regionBlock_sub1_sub7;block=begin;sub1=entryBlock]Class:  [regionBlock_sub1_sub7.category_id;]  - [regionBlock_sub1_sub7.category_name]
---------------------------------------------------------------------------------------------------
|[regionBlock_sub1_sub7_sub1.entry_number;block=tbs:row]|[regionBlock_sub1_sub7_sub1.entry_detail]|
---------------------------------------------------------------------------------------------------
[regionBlock_sub1_sub7.category4;block=end]
------------------------------------------------------------------------------------------------------------------------------
|[regionBlock_sub1_sub8.results_txt1;block=tbs:row]|[regionBlock_sub1_sub8.results_txt2]|[regionBlock_sub1_sub8.results_txt3]|
------------------------------------------------------------------------------------------------------------------------------
[regionBlock_sub1.sectionBlock;block=end]
-----------------------------------------------------------------------------------
|[regionBlock_sub2.group_results1;block=tbs:row]|[regionBlock_sub2.group_results2]|
-----------------------------------------------------------------------------------
[regionBlock;block=end]

Here is an example of merged data - note the 3 blank lines before start of "Section: District Two" and again before "Section Winner":...

Region: 1 - Northern Region
Judges: Mr Smith and Mr Jones
Section: District One
Category:  2  - Category Two
-----------
|1|Entry 1|
-----------
|2|Entry 2|
-----------
|3|Entry 3|
-----------

----------------
|1st:|2nd:|3rd:|
----------------
|    |    |    |
----------------



Section: District Two
Category:  1  - Category One
-----------
|4|Entry 4|
-----------
|5|Entry 5|
-----------
|6|Entry 6|
-----------

----------------
|1st:|2nd:|3rd:|
----------------
|    |    |    |
----------------
Category:  2  - Category Two
-----------
|7|Entry 7|
-----------
|8|Entry 8|
-----------
|9|Entry 9|
-----------

----------------
|1st:|2nd:|3rd:|
----------------
|    |    |    |
----------------



--------------------------
|Section Winner:|        |
--------------------------
By: Skrol29
Date: 2016-10-13
Time: 10:11

Re: Unwanted line breaks

Hi Owen,

With TBS, it is better to favor the relative syntax.
  http://www.tinybutstrong.com/manual.php#html_block

This is specially true with OpenTBS because the fields with "block=begin" and "block=end" can take some strange places or imply some contents like line-breaks.

If your sections are table rows, then you can use "block=tbs:row", if it is paragraph you can use "block=tbs:p".
By: Owen
Date: 2016-10-16
Time: 07:37

Re: Unwanted line breaks


Thanks for the help. I tried the relative and simplified syntax examples from your linked manual page, but didn't work for me:
TEMPLATE...<tag_name...>...[BlockName;block=tag_name;params]...</tag_name...>...TEMPLATE
and
TEMPLATE...<tag_name...>...[BlockName.ColumnName;block=tag_name;params]...</tag_name...>...TEMPLATE

...when I added XML tags to try defining each block's zone, the XML tags were ignored and remain in the merged document... and nesting of XML tags for the zones of sub-blocks didn't work for me either.  Do the XML tags used as above apply to DOCX format? 

> If your sections are table rows, then you can use "block=tbs:row", if it is paragraph you can use "block=tbs:p".

...I understand the suggestion about not declaring absolute begin/end of each block, but couldn't find examples of relative syntax used with multiple levels of sub-blocks and don't see how I would apply the "block=tbs:row" & "block=tbs:p" to my template.  Do you mean that each sub block that is declared requires either a paragraph or row declaration as well?  So in my example, instead of...

[regionBlock;block=begin;sub1=sectionBlock;sub2=sectionResults]Region: [regionBlock.#] - [regionBlock.region_name;noerr]
Judges: [regionBlock.group_judge_name;noerr][regionBlock_sub1;block=begin;sub1=(category1);sub2=(results1);sub3=(category2);sub4=(results2);sub5=(category3);sub6=(results3);sub7=(category4);sub8=(results4)]

I should have...
[regionBlock;block=tbs:p+tbs:p+tbs:row;sub1=sectionBlock;sub2=sectionResults]Region: [regionBlock.#] - [regionBlock.region_name;noerr]
Judges: [regionBlock.group_judge_name;noerr][regionBlock_sub1;block=tbs:p+tbs:row+tbs:row+tbs:row+tbs:row+tbs:row+tbs:row+tbs:row+tbs:row;sub1=(category1);sub2=(results1);sub3=(category2);sub4=(results2);sub5=(category3);sub6=(results3);sub7=(category4);sub8=(results4)]

etc.?
By: Skrol29
Date: 2016-10-16
Time: 23:24

Re: Unwanted line breaks

Hi,

Using OpenTBS you must not add your own tags, simply because that will not be XML tags. Only escaped text that will display strings.

With OpenTBS you can use the relative syntax with XML that is inner. Since it's difficult to know inner XML elements, OpenTBS gives alias for you : tbs:row, tbs:p (paragraph) , tbs:page,....

For advanced XML, they is an help file: http://www.tinybutstrong.com/plugins/opentbs/xml_synopsis.html
By: Owen
Date: 2016-11-02
Time: 06:31

Re: Unwanted line breaks

Thanks again for the response.  I understand your statement about using OpenTBS aliases for inner XML elements, and have read the XML synopsis, and have been trying ever since to apply the necessary logic... but still cannot resolve the relative syntax required in the template to merge the multiple levels of (conditional) sub-blocks.

Where the explicit syntax merged all the sub-blocks perfectly (albeit with some unwanted spacing - see merged result in original post above) the relative syntax seems to result in sub-blocks being repeated a set number of times in the merged document regardless of whether each sub-block contains data or how many array elements it contains.

e.g.:
adding
tbs:page+tbs:p+tbs:p+tbs:table;
to the 'Region' block and
tbs:p+tbs:p;
to the 'Section' sub-block etc. in the template results in the following output:

Region: 1 - Northern Region
Judges: Mr Smith and Mr Jones
Section:District One
Category:  -
Section:District Two
Category: 1 - Category One
followed by the rest of the template sub-blocks unmerged, followed by...
Region: 2 - Southern Region
Judges: Mrs Warner and Mr Jackson
Section:District A
Category:  -
Section:District B
Category:  -
followed again by the rest of the template sub-blocks repeated unmerged. 

Similarly, appending
+tbs:table;
to the main regionBlock for each possible level of sub-block that can contain table rows just results in un-merged blocks in the output.

You can see from the first post in this thread the original template with correct merge result.  But changing to relative syntax it starts going wrong in the first level of sub-blocks.  I can't find any similar example in the documentation that suggests the correct use of relative syntax to handle the 3 levels of sub-blocks I'm using, some of which are conditional - would you able to provide any pointers as to the required syntax in the template? 

The sample array I'm merging to simulate the data is:
$regionBlock = array (
  0 =>
  array (
    'group_number' => '1',
    'region_name' => 'Northern Region',
    'group_judge_name' => 'Mr Smith and Mr Jones',
    'sectionBlock' =>
    array (
      0 =>
      array (
        'section_name' => 'District One',
        'category2' =>
        array (
          0 =>
          array (
            'category_id' => '2',
            'category_name' => 'Category Two',
            'entryBlock' =>
            array (
              0 =>
              array (
                'entry_number' => 1,
                'entry_detail' => 'Entry 1',
              ),
              1 =>
              array (
                'entry_number' => 2,
                'entry_detail' => 'Entry 2',
              ),
              2 =>
              array (
                'entry_number' => 3,
                'entry_detail' => 'Entry 3',
              ),
            ),
          ),
        ),
        'results2' =>
        array (
          0 =>
          array (
            'results_txt1' => '1st:',
            'results_txt2' => '2nd:',
            'results_txt3' => '3rd:',
          ),
          1 =>
          array (
            'results_txt1' => ' ',
            'results_txt2' => ' ',
            'results_txt3' => ' ',
          ),
        ),
      ),
      1 =>
      array (
        'section_name' => 'District Two',
        'category1' =>
        array (
          0 =>
          array (
            'category_id' => '1',
            'category_name' => 'Category One',
            'entryBlock' =>
            array (
              0 =>
              array (
                'entry_number' => 4,
                'entry_detail' => 'Entry 4',
              ),
              1 =>
              array (
                'entry_number' => 5,
                'entry_detail' => 'Entry 5',
              ),
              2 =>
              array (
                'entry_number' => 6,
                'entry_detail' => 'Entry 6',
              ),
            ),
          ),
        ),
        'results1' =>
        array (
          0 =>
          array (
            'results_txt1' => '1st:',
            'results_txt2' => '2nd:',
            'results_txt3' => '3rd:',
          ),
          1 =>
          array (
            'results_txt1' => ' ',
            'results_txt2' => ' ',
            'results_txt3' => ' ',
          ),
        ),
        'category2' =>
        array (
          1 =>
          array (
            'category_id' => '2',
            'category_name' => 'Category Two',
            'entryBlock' =>
            array (
              0 =>
               array (
                'entry_number' => 7,
                'entry_detail' => 'Entry 7',
              ),
              1 =>
              array (
                'entry_number' => 8,
                'entry_detail' => 'Entry 8',
              ),
              2 =>
              array (
                'entry_number' => 9,
                'entry_detail' => 'Entry 9',
              ),
            ),
          ),
        ),
        'results2' =>
        array (
          0 =>
          array (
            'results_txt1' => '1st:',
            'results_txt2' => '2nd:',
            'results_txt3' => '3rd:',
          ),
          1 =>
          array (
            'results_txt1' => ' ',
            'results_txt2' => ' ',
            'results_txt3' => ' ',
          ),
        ),
      ),
    ),
    'sectionResults' =>
    array (
      0 =>
      array (
        'group_results1' => 'Section Winner:',
        'group_results2' => ' ',
      ),
    ),
  ),
  1 =>
  array (
    'group_number' => '2',
    'region_name' => 'Southern Region',
    'group_judge_name' => 'Mrs Warner and Mr Jackson',
    'sectionBlock' =>
    array (
      0 =>
      array (
        'section_name' => 'District A',
        'category2' =>
        array (
          0 =>
          array (
            'category_id' => '2',
            'category_name' => 'Category Two',
            'entryBlock' =>
            array (
              0 =>
              array (
                'entry_number' => 10,
                'entry_detail' => 'Entry 10',
              ),
              1 =>
              array (
                'entry_number' => 11,
                'entry_detail' => 'Entry 11',
              ),
              2 =>
              array (
                'entry_number' => 12,
                'entry_detail' => 'Entry 12',
              ),
            ),
          ),
        ),
        'results2' =>
        array (
          0 =>
          array (
            'results_txt1' => '1st:',
            'results_txt2' => '2nd:',
            'results_txt3' => '3rd:',
          ),
          1 =>
          array (
            'results_txt1' => ' ',
            'results_txt2' => ' ',
            'results_txt3' => ' ',
          ),
        ),
      ),
      1 =>
      array (
        'section_name' => 'District B',
        'category2' =>
        array (
          0 =>
          array (
            'category_id' => '1',
            'category_name' => 'Category Two',
            'entryBlock' =>
            array (
              0 =>
              array (
                'entry_number' => 13,
                'entry_detail' => 'Entry 13',
              ),
              1 =>
              array (
                'entry_number' => 14,
                'entry_detail' => 'Entry 14',
              ),
              2 =>
              array (
                'entry_number' => 15,
                'entry_detail' => 'Entry 15',
              ),
            ),
          ),
        ),
        'results2' =>
        array (
          0 =>
          array (
            'results_txt1' => '1st:',
            'results_txt2' => '2nd:',
            'results_txt3' => '3rd:',
          ),
          1 =>
          array (
            'results_txt1' => ' ',
            'results_txt2' => ' ',
            'results_txt3' => ' ',
          ),
        ),
        'category4' =>
        array (
          1 =>
          array (
            'category_id' => '4',
            'category_name' => 'Category Four',
            'entryBlock' =>
            array (
              0 =>
              array (
                'entry_number' => 16,
                'entry_detail' => 'Entry 16',
              ),
              1 =>
              array (
                'entry_number' => 17,
                'entry_detail' => 'Entry 17',
              ),
              2 =>
              array (
                'entry_number' => 18,
                'entry_detail' => 'Entry 18',
              ),
            ),
          ),
        ),
        'results4' =>
        array (
          0 =>
          array (
            'results_txt1' => '1st:',
            'results_txt2' => '2nd:',
            'results_txt3' => '3rd:',
          ),
        ),
      ),
    ),
    'sectionResults' =>
    array (
      0 =>
      array (
        'group_results1' => 'Section Winner:',
        'group_results2' => ' ',
      ),
    ),
  ),
);