SimplePortal
Customization => Custom Coding => Topic started 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.
$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>';
-
maybe something like:
$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>';
-
Error message....
Syntax error in block code. Please check the code.
-
Sorry about that.
Try using the preview button to find out which line your error is in.
-
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.
-
But there is still a problem somewhere because it is ignoring the column widths.
Your $data['width'] output is empty.
-
Oops. Maybe you can fill that in?
-
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.
$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>';