PDA

View Full Version : Fetching different templaets w/ same eval() statement???


Antivirus
06-02-2008, 04:53 PM
I have the following 3 different eval statements based upon a conditional...


foreach ($sc_gblockinfo AS $sc_gblock)
{
if ($sc_gblock['pos'] == 'top')
{
eval('$sc_gblockbits_top .= "' . fetch_template('sc_gblock_edit_bit') . '";');
}
else if ($sc_gblock['pos'] == 'left')
{
eval('$sc_gblockbits_left .= "' . fetch_template('sc_gblock_edit_bit') . '";');
}
else if ($sc_gblock['pos'] == 'right')
{
eval('$sc_gblockbits_right .= "' . fetch_template('sc_gblock_edit_bit') . '";');
}
}



however i know it could be written more efficiently, and I have tried the following, along with different variations, however I just can't seem to figure it out...

foreach ($sc_gblockinfo AS $sc_gblock)
{
eval('$sc_gblockbits_' . $sc_gblock['pos'] . ' .= "' . fetch_template('sc_gblock_edit_bit') . '";');
}


Within the loop, $sc_gblock['pos'] can be one of three possibilities, 'top', 'left', or 'right'... I'm basically just looking for a more compact way of writing the first example above.

Anyone got an idea of how to do this correctly?

Opserty
06-02-2008, 04:58 PM
Doesn't it work? It seems correct to me, what errors if any do you receive?

Antivirus
06-02-2008, 05:14 PM
jeez, im in tard mode today - i was saving the plugin to the wrong hook. It is working, I was pulling my hair ou earlier thinking it was the code, lol - thanks Opserty :)

Opserty
06-02-2008, 09:10 PM
Haha, no problem ;)