Home

Icon Link in Laravel 4

Can someone help rewrite this, from HTML to Laravel4?

<a href="index.php" ><span><i class="icon-home"></i></span> Home </a> 

The route name for this page is simply "/". I know how to write a simple link in Laravel:

 {{ HTML::link('/','Home) }} 

But how can I add a span class with a font-awesome icon?

+8
html hyperlink laravel laravel-4 font-awesome
source share
3 answers

I would just put the link in href.

 <a href="{{ url('/') }}"><span><i class="icon-home"></i></span> Home</a> 

No need to generate anything else through Laravel.

+9
source share

What @Dries offers is simple and very simple, but you really want it to be done completely through Laravel, I would suggest writing an HTML macro, especially if you want to use more complex html structures. For example, here is a macro for the <a><img /></a> structure:

  HTML::macro('image_link', function($url = '', $img='img/', $alt='', $param = false, $active=true, $ssl=false) { $url = $ssl==true ? URL::to_secure($url) : URL::to($url); $img = HTML::image($img,$alt); $link = $active==true ? HTML::link($url, '#', $param) : $img; $link = str_replace('#',$img,$link); return $link; }); 

You can read more about this here: http://forums.laravel.io/viewtopic.php?pid=10467

+3
source share
 {!! HTML::decode(link_to(URL::previous(), '<i class="fa fa-chevron-left" aria-hidden="true"></i> Back', ['class' => 'btn btn-primary'])) !!} 
0
source share

All Articles