【问题标题】:Add twitter bootstrap icon to linkRoute将 twitter 引导图标添加到 linkRoute
【发布时间】:2014-05-28 06:18:43
【问题描述】:

想知道如何将图标添加到 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) }}

【问题讨论】:

  • 这应该可行 - 你得到的确切 HTML 是什么?
  • 这应该不起作用,因为 '
  • 改用宏自定义宏。
  • @deczo 我的错。我本可以发誓我以前就这样做过,而且效果很好。一定是在想别的。

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


【解决方案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 并在app/starts/global.php 文件中使用require 添加此文件,只需在global.php 的末尾添加require 即可:

require '/macros.php';

【讨论】:

  • 这不是更简单的方法吗?看起来很重的东西。
  • 我想,正如回答者所建议的,更简单的方法是使用裸 html:&lt;a href="{{{ URL::route('edit_data', array($data-&gt;id)) }}}"&gt;&lt;span class="glyphicon glyphicon-edit"&gt;&lt;/span&gt;&lt;/a&gt;
【解决方案2】:

如果你使用的是控制器,那么你可以使用 action helper 函数;喜欢:

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

【讨论】:

    【解决方案3】:

    试试 URL::route()

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

    【讨论】:

      猜你喜欢
      • 2013-03-08
      • 2014-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-01
      • 2013-05-28
      • 1970-01-01
      • 2016-12-31
      相关资源
      最近更新 更多