Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Link with icon in Laravel 4

Can someone help to rewrite this, from HTML to Laravel4?

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

The route name for that page is just '/'. I know how to write simple link in Laravel:

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

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

like image 759
FrancescoMussi Avatar asked Oct 17 '13 13:10

FrancescoMussi


2 Answers

I'd just put the link in the href.

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

No need to generate all the rest through Laravel.

like image 162
Dries Vints Avatar answered Nov 10 '22 09:11

Dries Vints


What @Dries suggests is simple and very straightforward, but you really want to have it done entirely via Laravel, I would suggest writing a HTML macro, especially if you want more complex html structures to be involved. For example, here is a macro for <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 could read more about it here: http://forums.laravel.io/viewtopic.php?pid=10467

like image 3
Glad To Help Avatar answered Nov 10 '22 10:11

Glad To Help