public function li()
{
return _class('html')->li([
'name 1',
[
'name' => 'My name 2',
],
[
'name' => 'My name 3',
'link' => url('/@object/@action/@id/3'),
],
]);
}
public function li($data = [], $extra = [])
{
$extra['id'] = $extra['id'] ?: __FUNCTION__ . '_' . ++$this->_ids[__FUNCTION__];
$items = [];
foreach ((array) $data as $v) {
if ( ! is_array($v)) {
$body = $v;
$v = [];
} else {
$body = $v['body'] ?: $v['name'];
}
if ( ! strlen($body)) {
continue;
}
$class_item = $v['class'] ?: $extra['class_item'];
$badge = $v['badge'] ? ' <sup class="badge badge-' . ($v['class_badge'] ?: 'info') . '">' . $v['badge'] . '</sup>' : '';
$items[] = '<li class="' . ($class_item ? ' ' . $class_item : '') . '"' . ($v['id'] ? ' id="' . $v['id'] . '"' : '') . '>' . $badge . ($v['link'] ? '<a href="' . $v['link'] . '">' . $body . '</a>' : $body) . '</li>';
if (is_array($v['sub'])) {
$items[] = $this->li($v['sub'], $extra);
continue;
}
}
return '<ul' . _attrs(['id', 'class', 'style'], $extra) . '>' . implode(PHP_EOL, (array) $items) . '</ul>';
}