Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Add site name and/or site domain as CSS class to body tag.
Would assist when using same theme for two similar sites. Currently I am using both CSS Injector and Skinr to avoid issues where block numbers and node IDs clash.
Contextually declaring these classes would solve the issues.
EG: body.sitename-a #block-7 V body.sitename-b #block-7
Comments
Comment #1
Jeff Burnz CreditAttribution: Jeff Burnz commentedRight, do you mean for a multi-site? Sounds like smart idea to me.
Comment #2
Jeff Burnz CreditAttribution: Jeff Burnz commentedOK, this can be done quite easily in preprocess, pretty sure this variable never changes...
So this will make a body class as: .site-name-foobarsite
Thoughts?
Comment #3
BarwonHack CreditAttribution: BarwonHack commentedHi Jeff - Yes for multisite.
I'm building two sites (one a public site, the other an extranet) that share the same theme. Decided not to use domain module as it tends to un-necessarily complicate life (IMHO unless the actual content is shared).
Your solution sounds great.
The one issue I was concerned with was the class changing between environments (EG: dev.sitename V www.sitename). But then this could actually be quite useful. So perhaps declaring the sitename and the url would be best. then you could effectively style using just the siteName, just the siteURL or with multiselectors (EG: body.sitename.siteurl) if required.
Cheers Jeff ++
Comment #4
Jeff Burnz CreditAttribution: Jeff Burnz commentedI don't want to add the domain class due to performance reasons - the site name is available for free in the $vars array, however the domain name I have to "GET" and will incur the a cost, albeit very small cost its not a commonly used feature, so I am not sure it passes the cost/benefit ratio. I am very weary of performance overhead in this theme because its a large and complex theme, it's easy to get carried away with features. Right now the performance is good, very good actually, so even very small features such as the domain class are coming under scrutiny.
Comment #5
BarwonHack CreditAttribution: BarwonHack commentedTotally agree Jeff. Thanks again for all your great - and hard - work.
(Is this in now dev?)
Comment #6
Jeff Burnz CreditAttribution: Jeff Burnz commentedyes this is now in dev, 7.x-3.x, but it just go committed a short while ago, it can take 24hr for the downloadable archive to update.
Comment #7
Jeff Burnz CreditAttribution: Jeff Burnz commentedOk, so now I think we backport this to 7.x-2.x.
Comment #8
Jeff Burnz CreditAttribution: Jeff Burnz commentedFixed in 2x.
Comment #8.0
Jeff Burnz CreditAttribution: Jeff Burnz commentedAdd ID to block CSS example