将twitter bootstrap图标添加到linkRoute

时间:2014-04-14 10:17:20

标签: twitter-bootstrap laravel laravel-4 icons blade

想知道如何将图标添加到Linkroute。

{{ HTML::linkRoute('edit_data', 'Edit', $data->id) }}

我希望编辑显示:

 <span class="glyphicon glyphicon-edit"></span>

我试过这个,但那不起作用:

{{ HTML::linkRoute('edit_data', '<span class="glyphicon glyphicon-edit"></span>', $data->id) }}

3 个答案:

答案 0 :(得分:1)

这不会起作用,您可以使用HTML代码而不是此功能,或者像这样创建custom macro

HTML::macro('iLinkRoute', function($name, $title = null, $parameters = array(), $attributes = array(), $html = ''){
    $url = route($name, $parameters);
    if (is_null($title) || $title === false) $title = $url;
    return "<a href = '$url'>$html.$title</a>" ;
});

然后像这样使用它:

{{ HTML::iLinkRoute('user.show.profile', 'Profile', ['username' => 'heera'], [] , '<span class="glyphicon glyphicon-edit"></span>') }}

生成的输出:

<a href="http://blog.dev/user/heera"><span class="glyphicon glyphicon-edit"></span>.Profile</a>

您可以将macro保留在filters.php或创建macros.php文件,然后使用require app/starts/global.php文件中的global.php添加此文件,只需添加在require '/macros.php';

结尾处要求
{{1}}

答案 1 :(得分:1)

如果您正在使用控制器,那么您可以使用动作助手功能;像:

<a href={{ action('HomeController@showHome', $params) }}>
 <span class="glyphicon glyphicon-edit"></span>
</a>

答案 2 :(得分:0)

尝试使用URL :: route()

<a href="{{URL::route('edit_data', array($data->id))}}"> <span class="glyphicon glyphicon-edit"></span> Text </a>