2014-04-14 32 views
0

想知道如何将图标添加到Linkroute。将twitter引导图标添加到链接路由

{{ 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) }} 
+0

这应该工作 - 你得到什么确切的HTML? – alexrussell

+1

这不应该起作用,因为'

+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> 

你可能在你的filters.phpmacro或创建文件作为macros.phpapp/starts/global.php文件中添加使用require这个文件,只需在global.php末尾添加要求:

require '/macros.php'; 
+0

这不是一个更简单的方法吗?看起来很重。 – user3270211

+4

我想如同回答者所建议的那样,更简单的方法是使用裸html:'' – alexrussell

+0

这很好用!谢谢! @alexrussell – user3270211

1

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

<a href={{ action('[email protected]', $params) }}> 
<span class="glyphicon glyphicon-edit"></span> 
</a> 
0

尝试网址::路线()

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