Categories > TinyButStrong general >

Skip or hold alternative block selection on certain data

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: RwD
Date: 2006-11-15
Time: 23:26

Skip or hold alternative block selection on certain data

In my template I use a duplicate block to achieve alternative row colors.
<li class="altColor1 color">[something.type]">[something.type; block=li]</li>
<li class="altColor2 color">[something.type]">[something.type; block=li]</li>
The data that is merged in are rows that can be of two types; 'normal' or 'special'. I need the alternative colors to go on as usual for the type normal. But if the type is special I need the program to not switch the block code.

What happens now is that is the type is special I style it to be purple where the normal type alternates between grey and white. In this way I can get the following color sequence: grey, white, grey, white, purple, white, grey. But this doesn't look good. I would like it to be: grey, white, grey, white, purple, grey, white.

Is this possibe using the normal tbs code or should I solve this on the php side?
By: Skrol29
Date: 2006-11-16
Time: 01:22

Re: Skip or hold alternative block selection on certain data

Hi,

This is not a trivial alternated coloring. It is smart and needs a custom algorithm. You have to do it at the PHP side. A good place can be an function for the parameter "ondata".
By: RwD
Date: 2006-11-16
Time: 22:18

Re: Skip or hold alternative block selection on certain data

If someone else is trying this. If I would have to solve it on the php side I would simply iterate the array and add a row color value for every row. Might be a bit easier then an ondata function??

Or did this method get very simple and able to be object methods...
By: sheepy
Date: 2006-11-17
Time: 12:57

Re: Skip or hold alternative block selection on certain data

I did this with a custom plugin that do what you want with following syntax:

<li class="[something;zebra=grey,white]">[something.type; block=li; default]</li>
<li class="purple">[something.type; block=li; when [something.type]=special]</li>


The plugin is not finished (no doc, no optimisation, still in development) so I'll only post relevant code.

define('TBS_PLUS','clsTbsPlugInPlus');
$GLOBALS['_TBS_AutoInstallPlugIns'][] = TBS_PLUS; // Auto-install
class clsTbsPlugInPlus {
    function OnInstall() { return array('OnFormat'); }
    function OnFormat($FieldName,&$Value,&$PrmLst,&$TBS) {
      foreach ($PrmLst as $key => $param) {
        $key = strtolower($key);
        if ($key=='zebra') {
          static $zebra = array();
          $hash = sha1($param);
          if (!isset($zebra[$hash])) {
            $zebra[$hash] = array ( 'values'=>explode(',', $param), 'index'=>0 );
            $z = &$zebra[$hash];
            $index = 0;
          } else {
            $z = &$zebra[$hash];
            ++$z['index'];
          $index = &$z['index'];
          }
        if ($index >= sizeof($z['values'])) $index = 0;
        $Value = $z['values'][$index];
        }
      }
    }
}