与 Laravel 4 中的图标链接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19427657/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 08:34:29  来源:igfitidea点击:

Link with icon in Laravel 4

htmllaravellaravel-4hyperlinkfont-awesome

提问by FrancescoMussi

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

有人可以帮忙重写这个,从 HTML 到 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:

该页面的路由名称只是“/”。我知道如何在 Laravel 中编写简单的链接:

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

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

但是如何添加带有字体真棒图标的 span 类?

回答by Dries Vints

I'd just put the link in the href.

我只是把链接放在href中。

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

No need to generate all the rest through Laravel.

无需通过 Laravel 生成所有其余部分。

回答by Glad To Help

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:

@Dries 建议的内容很简单也很直接,但您确实希望完全通过 Laravel 完成,我建议您编写一个 HTML 宏,特别是如果您希望涉及更复杂的 html 结构。例如,这是一个<a><img /></a>结构宏:

    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

您可以在此处阅读更多相关信息:http: //forums.laravel.io/viewtopic.php?pid=10467

回答by Rajeev Dambal

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