Is it possible to get the view / layout name in the Laravel blade template (4)

I have a layout in which I want to add classes to the body, depending on which view is displayed, i.e.:

<body class="layout-default page-index">

I can do this in Twig quite easily (OctoberCMS uses Twig), but I see no way to do this with the Laravel Blade templates (which I prefer anyway).

I would prefer not to pass a variable to each View::makewith a view name, as that seems redundant.

+4
source share
1 answer

Good question, a very smart way to work with css. You would usually use this by adding classes to the body tag or main div container.

:

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

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

});

:

<?php echo str_replace('.','-',$view_name);?>

<?php echo str_replace('.','-',Route::currentRouteName());?>

, .

+6

All Articles