Skip to main content
Removed answer from the question + FIXED word in title.
Source Link

Add View Name to CSS Class on Body [FIXED]

I'm looking for a way to echo out the view name and place it in to the master template inside the body tag as a CSS Class.

The reason for this is I have some pages where certain CSS Elements need to change however inline code is inefficient and I don't really want to make a dedicated view for that one page.

So, for example, if I was to land on the home page the body tag would be:

<body class="home">

Where if I was to go to about the about us page, it would change to:

<body class="about">

Any help is greatly appreciated.

SOLUTION

Credit to Stuart who provided the solution below:

View::composer('*', function($view){
    View::share('view_name', $view->getName());
}); 

Echo the view:

{{ $viewname }}

Add View Name to CSS Class on Body [FIXED]

I'm looking for a way to echo out the view name and place it in to the master template inside the body tag as a CSS Class.

The reason for this is I have some pages where certain CSS Elements need to change however inline code is inefficient and I don't really want to make a dedicated view for that one page.

So, for example, if I was to land on the home page the body tag would be:

<body class="home">

Where if I was to go to about the about us page, it would change to:

<body class="about">

Any help is greatly appreciated.

SOLUTION

Credit to Stuart who provided the solution below:

View::composer('*', function($view){
    View::share('view_name', $view->getName());
}); 

Echo the view:

{{ $viewname }}

Add View Name to CSS Class on Body

I'm looking for a way to echo out the view name and place it in to the master template inside the body tag as a CSS Class.

The reason for this is I have some pages where certain CSS Elements need to change however inline code is inefficient and I don't really want to make a dedicated view for that one page.

So, for example, if I was to land on the home page the body tag would be:

<body class="home">

Where if I was to go to about the about us page, it would change to:

<body class="about">
added 225 characters in body; edited title
Source Link
Mat
  • 494
  • 7
  • 21

Add View Name to CSS Class on Body [FIXED]

I'm looking for a way to echo out the view name and place it in to the master template inside the body tag as a CSS Class.

The reason for this is I have some pages where certain CSS Elements need to change however inline code is inefficient and I don't really want to make a dedicated view for that one page.

So, for example, if I was to land on the home page the body tag would be:

<body class="home">

Where if I was to go to about the about us page, it would change to:

<body class="about">

Any help is greatly appreciated.

SOLUTION

Credit to Stuart who provided the solution below:

View::composer('*', function($view){
    View::share('view_name', $view->getName());
}); 

Echo the view:

{{ $viewname }}

Add View Name to CSS Class on Body

I'm looking for a way to echo out the view name and place it in to the master template inside the body tag as a CSS Class.

The reason for this is I have some pages where certain CSS Elements need to change however inline code is inefficient and I don't really want to make a dedicated view for that one page.

So, for example, if I was to land on the home page the body tag would be:

<body class="home">

Where if I was to go to about the about us page, it would change to:

<body class="about">

Any help is greatly appreciated.

Add View Name to CSS Class on Body [FIXED]

I'm looking for a way to echo out the view name and place it in to the master template inside the body tag as a CSS Class.

The reason for this is I have some pages where certain CSS Elements need to change however inline code is inefficient and I don't really want to make a dedicated view for that one page.

So, for example, if I was to land on the home page the body tag would be:

<body class="home">

Where if I was to go to about the about us page, it would change to:

<body class="about">

Any help is greatly appreciated.

SOLUTION

Credit to Stuart who provided the solution below:

View::composer('*', function($view){
    View::share('view_name', $view->getName());
}); 

Echo the view:

{{ $viewname }}
Source Link
Mat
  • 494
  • 7
  • 21

Add View Name to CSS Class on Body

I'm looking for a way to echo out the view name and place it in to the master template inside the body tag as a CSS Class.

The reason for this is I have some pages where certain CSS Elements need to change however inline code is inefficient and I don't really want to make a dedicated view for that one page.

So, for example, if I was to land on the home page the body tag would be:

<body class="home">

Where if I was to go to about the about us page, it would change to:

<body class="about">

Any help is greatly appreciated.