Link with icon in Laravel 4

橙三吉。 提交于 2019-12-09 10:27:17

问题


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?


回答1:


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.




回答2:


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




回答3:


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


来源:https://stackoverflow.com/questions/19427657/link-with-icon-in-laravel-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!