css - Laravel Set tab active in foreach -
how set tab page class 'active' in dynamical created list?
i have link 'toon alle' show records, when ik click link display different view. active tab remains on first link.
<ul class="nav nav-pills sort-source" data-sort-id="portfolio" data-option-key="filter"> <li data-option-value="*" class="active"> <a href="#" ng-click="getallrequests(1)">toon alle</a> </li> @foreach ($categories $categorie) <li data-option-value=".{{$categorie->namen}}" class=""> <a href="#" ng-click="getrequests({{$categorie->id}})" data-id="{{$categorie->id}}">{{$categorie->namen}} </a> </li> @endforeach </ul>
you can using custom facade
or html macro
if using laravel 4
. example assumes using named routes.
you can change route($route)
route::getcurrentroute()->getpath()
for macro in laravel 4
/* |-------------------------------------------------------------------------- | active state html macro |-------------------------------------------------------------------------- | | tests route against current url active state | if true, returns 'active' class name | usage: html::activestate('named.route') | */ html::macro('activestate', function ($route,$arguments=null,$class='active') { return strpos(request::url(), route($route,$arguments)) !== false ? $class : ''; });
for facade(if don't know facade & how create 1 read here
facade accessor
use illuminate\support\facades\facade; class activestate extends facade { protected static function getfacadeaccessor() { return 'activestate '; } }
facade main class
namespace app\helpers; class activestate { public function activestate($route,$arguments=null,$class='active') { return strpos(request::url(), route($route,$arguments)) !== false ? $class : ''; } }
facade service provider
app::bind('activestate ', function() { return new app\helpers\activestate ; });
then add new provider/alias laravel configuration files.
inside views <li class="{{activestate::activestate('route.name')}}">this li item</li>
Comments
Post a Comment