Skip to content
This repository has been archived by the owner on Oct 18, 2020. It is now read-only.

How to add icon to breadcrumbs? #34

Closed
thearabbit opened this issue Jun 6, 2014 · 8 comments
Closed

How to add icon to breadcrumbs? #34

thearabbit opened this issue Jun 6, 2014 · 8 comments

Comments

@thearabbit
Copy link

How to add icon to breadcrumbs.
Pl example.

@d13r
Copy link
Owner

d13r commented Jun 6, 2014

You could probably pass HTML (or maybe even an array) as the $title parameter and customise the template.

@d13r d13r closed this as completed Jun 6, 2014
@thearabbit
Copy link
Author

could you example for me?

@d13r
Copy link
Owner

d13r commented Jun 6, 2014

This is untested:

$breadcrumbs->push('<img src="home.png">Home', route('home'));

Template (replaced {{{ }}} with {{ }} to disable HTML escaping):

<li><a href="{{{ $breadcrumb->url }}}">{{ $breadcrumb->title }}</a></li>

You'd have to be sure to escape any titles from other sources with Laravel's e() function though.

I've opened #35 for possibly adding arbitrary data to breadcrumbs some time in the future which would make it easier and more flexible.

In the mean time you could try passing an array as the title as a workaround - but I'm not sure if it will work or not, again I haven't tested this.

$breadcrumbs->push(['title' => 'Home', 'icon' => 'home.png'], route('home'));
<li><a href="{{{ $breadcrumb->url }}}"><img src="{{{ $breadcrumb->title['icon'] }}}">{{{ $breadcrumb->title['title'] }}}</a></li>

@thearabbit
Copy link
Author

Very Thanks

@d13r
Copy link
Owner

d13r commented Oct 26, 2014

In 2.3.0 it's now possible to add arbitrary data in the third parameter:

$breadcrumbs->push('Home', route('home'), ['icon' => 'home.png']);
<li><a href="{{{ $breadcrumb->url }}}"><img src="{{{ $breadcrumb->icon }}}">{{{ $breadcrumb->title }}}</a></li>

@lloricode
Copy link

@davejamesmiller how about like this?

<?php

Breadcrumbs::register('admin.dashboard', function ($breadcrumbs)
{
    $breadcrumbs->push('<i class="fa fa-fw fa-dashboard"></i> Dashboard', route('admin.dashboard'));
});

@d13r
Copy link
Owner

d13r commented Nov 10, 2017

@lloricode Only if you create a custom template that doesn't escape the title - which is a security risk as you'll have to manually escape every title. Also it's best practice to keep the HTML in the view.

@lloricode
Copy link

@davejamesmiller hmm good idea, maybe just create a view

Thanks :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants