Cannot wrap link label in a tag
server102 opened this issue · 2 comments
server102 commented
Hi, I am trying to achieve this markup
<a href="home">
<i class="fa fa-home"><i>
<span>Home</span>
</a>
Created a custom menu-items layout like this
{% for item in items %}
<li>
<a href="{{ item.url() }}">
<span>{{ item.title|raw }}</span>
</a>
{% if item.hasChildren() %}
{% set childrenItems = { 'items': item.children() } %}
<ul>
{{ include('partials.sidebar.menu-items', childrenItems) }}
</ul>
{% endif %}
</li>
{% endfor %}
Then used the prepend method to add the icon
Menu::make('CustomMenu', function ($menu) {
$menu->home->prepend('<i class="fa fa-home"></i>')
});
but the span wraps both the icon and label
<a href="home">
<span>
<i class="fa fa-home"><i>
Home</span>
</a>
dustingraham commented
Take a look at: https://github.com/lavary/laravel-menu#attributes-and-callback-function-of-item
Seems to be doing the same thing you're looking to do.
$menu->add($item['text'],['title'=>$item['title']])
->append('</span>')
->prepend('<i class="fa '.$item['icon'].'"></i> <span>')
->link->attr($item['link_attribute']);
server102 commented
Thank you so much, this is exactly what I need.