将视图名称添加到主体上的CSS类 [英] Add View Name to CSS Class on Body

查看:37
本文介绍了将视图名称添加到主体上的CSS类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来回显视图名称,并将其作为CSS类放置在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.

原因是我有一些页面需要更改某些CSS元素,但是内联代码效率低下,我真的不想为该页面做专门的视图.

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">

推荐答案

添加到过滤器(或路由):

Add to filters (or routes):

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

然后您可以使用 $ view_name

这篇关于将视图名称添加到主体上的CSS类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆