IMPROVEMENT: Dynamic Body Class

5 views
Skip to first unread message

Andi North

unread,
Apr 24, 2013, 3:56:08 PM4/24/13
to silk...@googlegroups.com
Hi all,

It would be great for there to be a class (or classes) added to the body of the page based on one or more of the following criteria:
  • Template Name (i.e. default.html (template) would be <body class="temp-default">
  • Page Name (i.e. my-account.html would be <body class="my-account">
  • Page ID (like above but instead of <body class="my-account">, you could have <body class="page-id-12">)
I would also suggest allowing a <body class="user-logged-in"> for when a user is logged in so that you could change a user menu for instance.

Examples of existing usage:
WordPress uses a php function <?php body_class(); ?> to add several classes to the body tag. It is very useful to target specific templates quickly and easily without adding extra markup (i.e. <div>'s)

Hope this helps, if you want anymore information or use cases let me know.

Andi

Ross McDonald

unread,
Apr 24, 2013, 4:40:59 PM4/24/13
to silk...@googlegroups.com
Hi Andi.

Thanks for posting your thoughts.

This looks interesting, I've replied inline below.

Ross.

On Wednesday, 24 April 2013 at 20:56, Andi North wrote:

Hi all,

It would be great for there to be a class (or classes) added to the body of the page based on one or more of the following criteria:
  • Template Name (i.e. default.html (template) would be <body class="temp-default">
I am not sure I see immediately how template name could be used, could you elaborate ?
  • Page Name (i.e. my-account.html would be <body class="my-account">
I can see a use case already for putting the page name in as a class - it could help select the nav for the current page which we are not currently doing. 
  • Page ID (like above but instead of <body class="my-account">, you could have <body class="page-id-12">)
We don't currently have page id's so this one may not have a place with Silk at the moment. 
I would also suggest allowing a <body class="user-logged-in"> for when a user is logged in so that you could change a user menu for instance.
Would this one give you an edge, making things easier than they currently are ? 

Examples of existing usage:
WordPress uses a php function <?php body_class(); ?> to add several classes to the body tag. It is very useful to target specific templates quickly and easily without adding extra markup (i.e. <div>'s)
I think this kind of answers my question on templates above… based on differing templates you are currently doing some 'div foo' to jiggle things around… this would be eased if the template name were a class on the body ? 

Hope this helps, if you want anymore information or use cases let me know.

Andi

--
You received this message because you are subscribed to the Google Groups "Silk Web Toolkit User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to silk-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Barrie McGuire

unread,
Apr 24, 2013, 4:43:15 PM4/24/13
to silk...@googlegroups.com
Some interesting suggestions, but you've got to be careful that we don't create a Silk DSL here - the original intent was always to have zero semantic pollution, just pure markup. 

Kind Regards,
Barrie McGuire

----------------------------------

BHEAP LIMITED
Unit 33
1 Winnall Valley Road
Winchester
Hampshire
SO23 0LD

Registration Number: 07510939
Registered in England and Wales

Andi North

unread,
Apr 24, 2013, 4:47:23 PM4/24/13
to silk...@googlegroups.com
Hi Ross,

With regards to your questions and answers, the ID is an understandable one. Not the most useful either.

With regards to the the template names and page name - they are really useful, as shown by WordPress (an in use example would be: http://1064070780.n68569.test.prositehosting.co.uk/) where the body classes are used to style other elements around the page - i.e. a sidebar is made slightly narrower for one specific template; on another template the heading styles are changed using the body class.

The user-logged-in would be helpful but nowhere as near as helpful as the pagename or template name classes would be.

Andi

Andi North

unread,
Apr 24, 2013, 4:48:57 PM4/24/13
to silk...@googlegroups.com
It would be useful if the body classes could be added like a component is. Only added when necessary. That way you avoid the code bloat that would be associated with other projects.

It's probably something that should have been added to my original comment :)

Andi

Ross McDonald

unread,
Apr 24, 2013, 5:03:53 PM4/24/13
to silk...@googlegroups.com
This looks like one or two classes specified on 'body' so zero pollution from a semantic perspective.  It looks like we would just be refining inherited styles to suit differing templates and it looks like it may prove an efficient solution for our lack of nav highlighting.

I guess the balance that needs to be found is just using this for a couple of really useful purposes, so we don't get a splatting of classes used in places where they are not relevant.

Ross.

Ross McDonald

unread,
Apr 24, 2013, 5:10:51 PM4/24/13
to silk...@googlegroups.com
Yes, it would be useful if we could turn this on/off easily, then it would not need to affect sites where it is not required.  Some kind of config maybe.

It is easy to add straight up, a little harder to add configurably.

We'll figure something out… I'll add it to the issues list on Github.

Ross.

Reply all
Reply to author
Forward
0 new messages