How can I get the current view name inside the master plan in Laravel 4?

in Laravel 4 I have a layout for the main blade and I want to add a class to the html element, for example, tpl-home, but I need to know what name of the current view is called View :: make.

<!doctype html>
<html lang="es" class="tpl-{{Str::slug($currentViewName)}}">

Does Laravel provide any function to get this?

thank

+3
source share
2 answers

Inside your filter file:

View::composer('*', function($view){

    View::share('view_name', $view->getName());

});

Then in your layout of the main blade you can access it as $ view_name.

+11
source

View Composers - / , , , , ,

Request::path() == 'viewName' Blade :

<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>
  ...
+3

All Articles