SimplePortal

Customization => Custom Coding => Topic started by: ehsizzup on May 24, 2010, 09:19:19 PM

Title: Blocks in Block Question - Easy PHP stuff but beyond me
Post by: ehsizzup on May 24, 2010, 09:19:19 PM
Using block in block coding as described in http://simpleportal.net/index.php?topic=5332.0

I would like to add something to the code below so that I can set each column width as a percentage.

It would seem that I need to create an array for the widths and change the  "100 / $columns" in line 36 to the column width from the array. 

Easy for me to describe, but can't figure it out.

Help please and thank you.

Code: [Select]
$columns = 2;
$block_ids = array(225,224);

$block_data = array();
foreach ($block_ids as $block)
{
   $block_data[$block] = current(getBlockInfo(false, $block, false, false));
   $block_data[$block]['style'] = sportal_parse_style('explode', $block_data[$block]['style'], true);
}

echo '
<table style="width: 100%; overflow:hidden; cellpadding: 0; margin: 0 0 0 0;">
   <tr>';

$counter = 0;
foreach ($block_data as $data)
{
   if ($counter != 0 && $counter % $columns == 0)
   {
      echo '
   </tr>
   <tr>';
   }

   echo '
      <td style="width: ', ceil((100 / $columns)), '%; vertical-align: top;">
         ', template_block($data), '
      </td>';

   $counter++;
}

echo '
   </tr>
</table>';
Title: Re: Blocks in Block Question - Easy PHP stuff but beyond me
Post by: AngelinaBelle on May 24, 2010, 10:27:14 PM
maybe something like:
Code: [Select]
$columns = 2;

$block_inputs=array(
                       array('id' => 225, 'width' =>50),
                       array('id' => 224, 'width' => 50),
                    );

$block_data = array();
foreach ($block_inputs as $block)
{
   $block_data[$block['id']] = current(getBlockInfo(false, $block['id'], false, false));
   $block_data[$block['id']]['style'] = sportal_parse_style('explode', $block_data[$block['id]]['style'], true);
   $block_data[$block['id']]['width'] = $block[$block['width']]
}

echo '
<table style="width: 100%; overflow:hidden; cellpadding: 0; margin: 0 0 0 0;">
   <tr>';

$counter = 0;
foreach ($block_data as $data)
{
   if ($counter != 0 && $counter % $columns == 0)
   {
      echo '
   </tr>
   <tr>';
   }

   echo '
      <td style="width: ', $data['width'], '%; vertical-align: top;">
         ', template_block($data), '
      </td>';

   $counter++;
}

echo '
   </tr>
</table>';
Code: [Select]


Code: [Select]
Title: Re: Blocks in Block Question - Easy PHP stuff but beyond me
Post by: ehsizzup on May 24, 2010, 11:13:03 PM
Error message....


Code: [Select]
Syntax error in block code. Please check the code.
Title: Re: Blocks in Block Question - Easy PHP stuff but beyond me
Post by: AngelinaBelle on May 25, 2010, 08:06:01 AM
Sorry about that.
Try using the preview button to find out which line your error is in.
Title: Re: Blocks in Block Question - Easy PHP stuff but beyond me
Post by: ehsizzup on May 25, 2010, 10:34:53 AM
Wow.  I learn something new every day.  I didnt know that Preview will show the error information.  That helps a lot.

Error on line 12 - missing ' after an ID.
Error on line 14 - missing ; at end of line.
Title: Re: Blocks in Block Question - Easy PHP stuff but beyond me
Post by: ehsizzup on May 25, 2010, 10:36:31 AM
But there is still a problem somewhere because it is ignoring the column widths.

Your $data['width'] output is empty.

 
Title: Re: Blocks in Block Question - Easy PHP stuff but beyond me
Post by: AngelinaBelle on May 25, 2010, 11:09:54 AM
Oops.  Maybe you can fill that in?
Title: Re: Blocks in Block Question - Easy PHP stuff but beyond me
Post by: ehsizzup on May 25, 2010, 02:23:31 PM
Got it.  You had one too many offset layers on line 10...now reads

   $block_data[$block['id']]['width'] = $block['width'];

Thanks for making me work for it at the end.  I think I learned a few things.

Final Code....just make sure your widths total 100% or you will get some unpredictable results.


Code: [Select]
$block_inputs=array(
                       array('id' => 225, 'width' => 40),
                       array('id' => 224, 'width' => 60),
                    );
$block_data = array();
foreach ($block_inputs as $block)
{
   $block_data[$block['id']] = current(getBlockInfo(false, $block['id'], false, false));
   $block_data[$block['id']]['style'] = sportal_parse_style('explode', $block_data[$block['id']]['style'], true);
   $block_data[$block['id']]['width'] = $block['width'];
}

echo '
<table style="width: 100%; overflow:hidden; cellpadding: 0; margin: 0 0 0 0;">
   <tr>';

$counter = 0;
foreach ($block_data as $data)
{
   if ($counter != 0 && $counter % $columns == 0)
   {
      echo '
   </tr>
   <tr>';
   }

   echo '
      <td style="width: ', $data['width'], '%; vertical-align: top;">
         ', template_block($data), '
      </td>';

   $counter++;
}

echo '
   </tr>
</table>';
SimplePortal 2.3.8 © 2008-2024, SimplePortal