Hey all - I put this plugin together for a site I’m working on, and figured I should offer it up for others.
ClassEE Body will apply several dynamic classes to your <body> tag. Use it like so in your template:
<body{exp:classee_body}>
That’s it. You’ll now get a classed-up <body> tag using URI segments, the current member group, type of archive page (category, paged, or monthly), current browser, and platform.
For example, if the current URI was:
http://mydomain.com/magazine/articles/c/politics/P20/
Your <body> tag would look like this:
<body class="magazine articles politics category paged P20 superadmin mac safari">
(In this case, you’d be logged-in as a SuperAdmin, your category keyword would be “c”, and you’d be browsing on a Mac using Safari.)
Member groups 1 through 5 will be classed using their group names (superadmin, banned, guest, pending, member), whereas custom member groups will be classed “groupid_N” (N being the member group ID).
Numeric URI segments (for example, when calling an entry via its entry_id) will be prepended with the letter “n”, i.e.
http://mydomain.com/magazine/articles/246
Would yield:
<body class="magazine articles n246 groupid7 firefox win">
Lastly, if there are no URI segments to be found, your <body> will get the class of “home”.
If you’d like to retreive only the class names, but not the class=”” attribute itelf, simply add attr=”false” as a parameter:
{exp:classee_body attr="false"}
Nice work D-Rock,
I built something similar (although a little less advanced) a while ago called LG Template Info.
I’ll be using this for sure.
Quick question tho. How many extra db calls are used to determine the body class attributes?
Hey Leevi - I should have it on GitHub actually, not sure why I didn’t think of that. I’ll get on that.
Re: “pages support” - how do you mean exactly? Do you mean a class called “page” when viewing an EE page? All URL segments get added as classes, so if you’re on a page at /about/contact/, for example, both ‘about’ and ‘contact’ will be added as classes.
Can you clarify? 😊
Aaah, gotcha. That’s a little beyond the scope of what I was hoping to do with the plugin right now - but maybe when I’m not so busy. I took a peek at your aforementioned plugin, and it seems like we could merge the two without too much effort. It does seem a shame to have to add DB calls to add the additional template classes though.
I did put ClassEE Body up on GitHub, after fighting with the Terminal and commit messages I couldn’t seem to save or delete or do anything with other than Command-Q-ing. (This is why I bought Versions for subversion needs!)
http://github.com/amphibian/pi.classee_body.ee_addon/
If you’re up for it, fork-away. 😊
ClassEE Body will apply several dynamic classes to your <body> tag. Use it like so in your template:That’s it. You’ll now get a classed-up <body> tag using URI segments, the current member group, and type of archive page (category, paged, or monthly).<body{exp:classee_body}>
Nice work!
It would be desirable if the plugin would not output the opening and closing tags (e.g. class=” “) and instead just output the actual data — exactly like the URL Segment Variables do.
There are many positives to this approach and perhaps it could be supported in a future release or by a parameter?
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.