public function navbar()
{
return _class('html')->navbar([
'brand' => [
'link' => url('/'),
'name' => 'Title',
],
[
'link' => url('/home'),
'name' => 'Home',
],
[
'link' => url('/link1'),
'name' => 'Link1',
],
[
'link' => url('/link2'),
'name' => 'Link2',
],
]);
}
public function navbar($data = [], $extra = [])
{
$extra['id'] = $extra['id'] ?: __FUNCTION__ . '_' . ++$this->_ids[__FUNCTION__];
$items = [];
$brand = '';
if (isset($data['brand'])) {
$b = $data['brand'];
unset($data['brand']);
$brand = '<a class="brand navbar-brand' . ($b['class'] ? ' ' . $b['class'] : '') . '" href="' . $b['link'] . '" title="' . $b['name'] . '">' . $b['name'] . '</a>';
}
$data = _prepare_html($data);
foreach ((array) $data as $k => $v) {
if (isset($extra['selected'])) {
$is_selected = ($extra['selected'] == $k);
} else {
$is_selected = (++$i == 1);
}
$class_item = $v['class_item'] ?: $extra['class_item'];
$badge = $v['badge'] ? ' <sup class="badge badge-' . ($v['class_badge'] ?: 'info') . '">' . $v['badge'] . '</sup>' : '';
$items[] = '<li class="' . ($is_selected ? ' active' : '') . ($class_item ? ' ' . $class_item : '') . '"><a href="' . $v['link'] . '" title="' . $v['name'] . '">' . $v['name'] . $badge . '</a></li>';
}
return
'<div class="navbar navbar-default' . ($extra['class'] ? ' ' . $extra['class'] : '') . '" id="' . $extra['id'] . '">
<div class="navbar-inner navbar-header">'
. $brand
. '<ul class="nav navbar-nav">' . implode(PHP_EOL, (array) $items) . '</a>
</div>
</div>';
}