I’m working on a bit of code which checks at the end if a keyword, description & title exists. If it doesn’t it displays the default value but the default value even though it exists wont display.
I think to start you could simplify this part at the top, at the bottom i didn’t monkey with
if (isset($hotel['tab']))
{
// Since map has a different name I did this here..
if ($hotel['tab'] == 'map')
{
$template->assign('pagetitle', $hotel['hotel']['hotel_resortplan_title']);
$template->assign('keywords', $hotel['hotel']['hotel_resortplan_keywords']);
$template->assign('description', $hotel['hotel']['hotel_resortplan_description']);
}
else
{
$template->assign('pagetitle', $hotel['hotel']["hotel_{$hotel['tab']}_title"]);
$template->assign('keywords', $hotel['hotel']["hotel_{$hotel['tab']}_keywords"]);
$template->assign('description', $hotel['hotel']["hotel_{$hotel['tab']}_description"]);
}
}
else {
// The rest of your else statement from your code
}
You could assign the default keywords to start, and get them out of that php else. In addition, just have ‘map’ remap the variable… and you can shorten the code considerably. Just like this.
// Assign Defaults
$template->assign('pagetitle', $hotel['hotel']['hotel_title']);
$template->assign('keywords', $hotel['hotel']['hotel_overview_keywords']);
$template->assign('description', $hotel['hotel']['hotel_overview_description']);
if (isset($hotel['tab'])) {
$tab = $hotel['tab']; /* Create a copy to work with.. incase you are using the real $hotel['tab'] var elsewhere */
// Remap to this one
if ($tab == 'map') {
$tab = 'resortplan';
}
if (isset($hotel['hotel']["hotel_{$tab}_title"])) {
$template->assign('pagetitle', $hotel['hotel']["hotel_{$tab}_title"]);
$template->assign('keywords', $hotel['hotel']["hotel_{$tab}_keywords"]);
$template->assign('description', $hotel['hotel']["hotel_{$tab}_description"]);
}
}