Add Class to html Macros Laravel Blade

I am new to laravel blade and I want to have an automatic active navigation bar, so I have this code

<li>{{ HTML::clever_link("index", 'Home' ) }}</li>
<li><a class="glow" href='breeder'>Breeder's Profile</a></li>
<li><a class="glow" href='gallery'>Gallery</a></li>
<li><a class="glow" href='contact'>Contact Us</a></li>

I used the clever link as I research to do what i want, but it remove the link class "glow" now I want to add the glow class to the li with the clever link, I tried this

<li>{{ HTML::clever_link("index", 'Home', class="glow" ) }}</li>

but it just gives me error. Thanks

Answers


You can simply add an argument to your HTML Macro: (Obviously I don't know how your macro looks like so this is just an example)

HTML::macro('clever_link', function($link, $label, $class = ''){
    return '<a href="'.$link.'" class="'.$class.'">'.$label.'</a>';
});

Usage:

{{ HTML::clever_link("index", 'Home', 'glow') }}

Or something a bit more flexible:

HTML::macro('clever_link', function($link, $label, $attributes = array()){
    return '<a href="'.$link.'" '.HTML::attributes($attributes).'>'.$label.'</a>';
});

Usage:

{{ HTML::clever_link("index", 'Home', array('class' => 'glow')) }}

(The HTML::attributes() method allows you to convert an array into an HTML attributes string)


 // for navigation menu highlight
HTML::macro('clever_link', function($route, $text, $icon) {    

if( Request::path() == $route ) {
        $active = "class = 'active'";
    }
      else {
        $active = '';
    }

  return "<a href = '{url($route)}' $active> <i class = '{$icon}'></i>{$text}</a>";
});

</pre>

Usage:
Make your menu as:

{{ HTML::clever_link("/", 'Home', 'icon-home-2') }}
{{ HTML::clever_link("/aboutus", 'About Us', 'icon-dollor') }}

in your menu's link

OR use

https://github.com/pyaesone17/active-state


Need Your Help

HTML automatically adding padding?

html css padding

My problem with this HTML script is that I'm always get a padding-bottom in each div. Can anybody see why?