I have this approach for now:
ctop = $cnew = $cmine = '';
if($actual == 'top') $ctop = 'class="active"';
if($actual == 'last') $new = 'class="active"';
if($actual == 'mine') $cmine = 'class="active"';
$html = '<aside class="panel_derecho">
<div class="tabs"><h4>$donde</h4>
<ul>';
$js = "refrescar_submenu('last_$donde')";
$js_t = "refrescar_submenu('top_$donde')";
$js_r = "refrescar_submenu('mine_$donde')";
$html .= '<li '.$ctop.'><a href="#sub_menu" onclick="'.$js_t.'">top</a></li>';
$html .= '<li '.$cnew.'><a href="#sub_menu" onclick="'.$js.'">ultimos</a></li>';
$html .= '<li '.$mine.'><a href="#sub_menu" onclick="'.$js_r.'">like</a></li>';
$html .= ' </ul>
</aside>';
return $html;
wich works as expected:
It generates a list with the desired copy, the desired javascript function parameter, and the active class (for the wanted one)
But i feel it could be less repetitive; and i can already see that it will be expensive to add/edit/remove copys, params, elements, etc.. i just don’t know where to beggin..
In case it helps:
$donderepresents the type of data (articles, songs, videos, ..)$actualrepresents one atribute (new articles, top articles,
articles i like)
1 Answer