问题
I have a bottom in twitter bootstrap but want to add a icon in the bottom. Is that possible ?
This is the button:
<div class="col-md-6">{{ HTML::linkRoute('change_log', 'Endringslogg', array(), array('class' => 'btn btn-primary')) }}</div>
Icon I want to add:
<span class="glyphicon glyphicon-user"></span>
回答1:
You can create a macro to handle this
HTML::macro('button', function($route, $title, $parameters = array(), $attributes = array())
{
$icon = array_get($attributes, 'icon');
$iconTag = $icon ? '<span class="glyphicon glyphicon-'.$icon.'"></span> ' : '';
if ($icon) unset($attributes['icon']);
return HTML::linkRoute($route, $iconTag.$title, $parameters, $attributes);
});
Then in your blade template do something like:
<div class="col-md-6">{{ HTML::button('change_log', 'Endringslogg', [], ['class' => 'btn btn-primary', 'icon' => 'user']) }}</div>
回答2:
You can create a helper which is not using HTML::linkRoute as this method encodes html entites so you would end up with this:
<a href="http://your.url"><span class="glyphicon glyphicon-user"></span></a>
And here's the helper
if ( ! function_exists('icon_link_to_route')) {
/**
* Create link to named route with glyphicon icon.
*
* @param string $icon
* @param string $route
* @param string $title
* @param array $parameters
* @param array $attributes
* @return string
*/
function icon_link_to_route($icon, $route, $title = null, $parameters = array(), $attributes = array())
{
$url = route($route, $parameters);
$title = (is_null($title)) ? $url : e($title);
$attributes = HTML::attributes($attributes);
$title .= '<span class="glyphicon glyphicon-'.e($icon).'"></span>';
return '<a href="'.$url.'"'.$attributes.'>'.$title.'</a>';
}
}
来源:https://stackoverflow.com/questions/23322989/add-twitter-bootstrap-icon-in-button