in Laravel 4 I have a master blade layout and I want to add a class to the html element like \'tpl-home\', but I need to know which is the current view name called with View
Inside your filters file place:
View::composer('*', function($view){
View::share('view_name', $view->getName());
});
Then in your master blade layout you can access it as $view_name.
View Composers are a great way to keep/share variables in views, but the names of the views set in routes file are more a fixed value in each view than a variable, that's why, in this case,
I'd rather use Request::path() == 'viewName'
in Blade like this:
<ul class="nav navbar-nav">
<li{{ Request::path() == 'admin' ? ' class="active"' : '' }}>
<a href="{{ URL::to('/admin') }}">Admin</a>
</li>
<li{{ Request::path() == 'bookings' ? ' class="active"' : '' }}>
<a href="{{ URL::to('/bookings') }}">Bookings</a>
</li>
...