无论如何,这可以简化吗?
<?php
$menu = JSite::getMenu();
$arr = (array)$menu->getActive();
$alias = $arr['alias'];
if ($alias == "accueil") {
echo('<h2 class="moduletitle"><span>title 1</h2></span>');
}
elseif ($alias == "welcome") {
echo('<h2 class="moduletitle"><span>title 2</h2></span>');
}
else {
echo "<h1 class='moduletitle'><span>";
echo $this->escape($this->params->get('page_title'));
echo "</span></h1>";
}
?>
答案 0 :(得分:1)
至少尝试使用switch而不是其他许多:
<?php
$menu = JSite::getMenu();
$arr = (array)$menu->getActive();
$alias = $arr['alias'];
$headingType = "h1";
switch ($alias) {
case 'accueil':
$headingType = "h2";
$title = "title 1";
break;
case 'welcome':
$headingType = "h2";
$title = "title 2";
break;
default:
$title = $this->escape($this->params->get('page_title'));
}
echo "<" . $headingType . " class=\"moduletitle\"><span>" .
$title .
"</span></" . $headingType . ">";