I’ve turned my sites menu into a site method to keep the snippet tidy. However, im getting a weird issue where a zero character is being created before the list item. I cant for the life of me figure out where that is coming from.
'siteMethods' => [
'sitemenu' => function ($btnclass = 'btn-small', $activeclass = 'active') {
$sitemenu = $this->menu()->toStructure();
$menu = '';
foreach ($sitemenu as $menu) {
$link = $menu->link()->toLinkObject();
$active = '';
if ($link->type() == 'page') {
$active = ($this->find($menu->link()->toLinkObject()->value())->isOpen()) ? $activeclass : '';
}
$link = Html::a($link->url(), $link->title(), ['title' => $link->title(), 'class' => $btnclass]);
$li = Html::tag('li', [$link], ['class' => $active]);
$menu .= $li;
}
return $menu;
}
]
Any idea? The menu links are in a structure field, and it makes use of the link-field plugin.
It’s gone now. Thanks.