Is it possible to get the view / layout name in a Laravel (4) blade template
laravel, laravel-blade, php, templates
Solution
Good question, very smart way to work with css. You would use this typically by adding classes to the body tag, or the main container div.
within your routes or filters file:
View::composer('*', function($view){
View::share('view_name', $view->getName());
});
Within your view:
<?php echo str_replace('.','-',$view_name);?>
<?php echo str_replace('.','-',Route::currentRouteName());?>
These should get you everything you need.
Problem
I have a layout in which I want to add classes to the body depending on which view is being displayed, i.e.: ``` <body class="layout-default page-index"> ``` I can do this in Twig quite easily (OctoberCMS uses Twig) but I can't see a way to do it with Laravel's Blade templates (which I prefer anyway). I'd rather not have to pass a variable to every `View::make` with the view name as this seems redundant.