Categories > TinyButStrong general >

Delete block when merge array has no data

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: TomH
Date: 2006-07-18
Time: 21:32

Delete block when merge array has no data

Hi
When I do a merge array like this
foreach($query AS $module){
    if($module->position=="right"){
    $blk_mod[$n]['num']="$n";
    $blk_mod[$n]['flag']="Flag=$n";
    ($module->type=="module") ? $blk_mod[$n]['mod_right_flag']="mod" : $blk_mod[$n]['mod_right_flag']="block" ;
    $descript = $module->descript;
    $blk_mod[$n]['descript']=$module->descript;
    $blk_mod[$n]['mod_url']=$module->categurl;
    }
$n++;
}
$TBS->MergeBlock('blk_mod', $blk_mod);

with html like this
  <rightblocks>   
     <td   bgcolor="#F7F7F7" rowspan=99 valign=top width="120">
         <module num="[blk_mod;block=module;noerr] [onshow; magnet=rightblocks]" >
                    <!-- * [blk_mod.mod_url] * [blk_mod.mod_right_flag] * [blk_mod.flag;block=module] * -->
                    [blk_mod.mod_url;script=[blk_mod.mod_url]; subtpl;]
         </module>                                                                           
    </td>
  </rightblocks>   


The html block "rightblocks" is NOT rendered as intended -- but I get error...
TinyButStrong Error when merging block [blk_mod] : unsupported variable type : 'NULL'.

Any ideas what is wrong with my code are very welcomed.
By: Skrol29
Date: 2006-07-18
Time: 22:03

Re: Delete block when merge array has no data

Hi TomH,

It seems that weh you have no data then $blk_mod is a null variable (your foreach loop is not visited). Unfortunately, TBS doesn't deals with null values. (it could but I'm always afraid that lot of users report lot of non merging block without checking that they have null variables).

So you just have to set :
  if (is_null($blk_mod)) $blk_mod = array();
before the MergeBlock().

By the way, your
   [onshow; magnet=rightblocks]
is surpising
By: TomH
Date: 2006-07-18
Time: 23:06

Re: Delete block when merge array has no data

Thanks, I see now why the NULL was doing it's mischief. I missed that there are two steps and that the one getting the rows was causing the NULL object instead of empty array. Fixed and works as expected now.

I do not understand observation:  [onshow;magnet=rightblocks] is surprising -- will you say more pls.

In any event the magnet was not working as intended. I am now doing
  <rightblocks>   
     <td   bgcolor="#F7F7F7" rowspan=99 valign=top width="120">
         <module name="[blk_mod;block=module]"  >
                    <!-- * [blk_mod.mod_url;nodata] [onshow; bmagnet=rightblocks] * [blk_mod.mod_right_flag] * [blk_mod.flag] * -->
                    [blk_mod.mod_url;script=[blk_mod.mod_url]; subtpl;]
         </module>                                                                           
        <module>[blk_mod;block=module;nodata] [onshow; magnet=rightblocks]</module>
    </td>
</rightblocks>
It seems to be working - although it does look clumsy - - do you have some thoughts about doing it simply, or more TBS correct?

By: Skrol29
Date: 2006-07-18
Time: 23:56

Re: Delete block when merge array has no data

Hi,

> I do not understand observation

It makes more sens now. But you can do it smarter if you are using with TBS 3. You can use parameter "bmarget=td".
Like this:
  <td   bgcolor="#F7F7F7" rowspan=99 valign=top width="120">
   <module name="[blk_mod;block=module;bmagnet=td]"  >
     <!-- * [blk_mod.mod_url] * [blk_mod.mod_right_flag] * [blk_mod.flag] * -->
     [blk_mod.mod_url;script=[blk_mod.mod_url]; subtpl;]
   </module>                 
</td>

And the first "nodata" in [blk_mod.mod_url;nodata] was unuseful.