Categories > OpenTBS with ODT >

How can I make a table disappear if there no data for that table?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: anagama
Date: 2012-07-12
Time: 23:25

How can I make a table disappear if there no data for that table?

I have no trouble getting data into tables from an array using MergeBlock.  However, I want the tables to disappear completely if a cell is empty (if one is empty, all will be).  My idea was to use the "magnet" tag to get rid of the table, but I must not be using it right, or not using the "block" part right (i've tried some variations to no avail).

The array is simple, just two keys ('fullName' and 'age'), both set to value '' when there is no data.

php:
$TBS->MergeBlock('people', $people);

ODT template:
cell_1: [people.fullName;block=table:table-row;magnet=table:table] cell_2:[people.age]

When there is data, it works great and the table fills out perfectly, but when there is no data, rather than having the table just disappear, I have a single row with two empty cells.  What should I be doing differently to make the table disappear completely?  Can I generate a table without making a table in my template?  Can I delete a table existing in my template if a cell is empty?

Thank you
By: Skrol29
Date: 2012-07-12
Time: 23:32

Re: How can I make a table disappear if there no data for that table?

"magnet" works only for TBS fields.
For a block it is "bmagnet".
By: anagama
Date: 2012-07-12
Time: 23:38

Re: How can I make a table disappear if there no data for that table?

Thanks for the quick response -- unfortunately, I have the same result with bmagnet.  Just tried again to be sure, but I had tried that earlier after going through this forum and forgot by the time I posted my question.
By: Skrol29
Date: 2012-07-12
Time: 23:50

Re: How can I make a table disappear if there no data for that table?

Hi,

I've tested your snippet with "bmagnet" and it worked correctly for me.

If you have an empty row with two empty cells, it probably means that you do have data with one blank row.
By: anagama
Date: 2012-07-13
Time: 00:24

Re: How can I make a table disappear if there no data for that table?

Hmmm -- it's so hard to see empty sets.  ;-)  I'll keep working on it.
By: anagama
Date: 2012-07-13
Time: 01:08

Re: How can I make a table disappear if there no data for that table?

You were absolutely right about my array having some sort of data in it.

So when my query returns nothing, rather setting the array that gets that data so that it has empty set values for the keys, I simply reset the array in total and it works. 

fails (i.e., leaves empty table in document):
$people[]=array('fullName'=>'', 'age'=>'');

works (i.e., table disappears totally):
$people=array();

Many thanks for putting me on the right track.