This project is read-only.

Conditional CSS Class in Layer

Topics: Writing modules, Writing themes
Dec 13, 2013 at 4:47 PM
Edited Dec 13, 2013 at 4:48 PM
I am trying to add a css class to a div in my theme only in certain layers.

1) Is there a way to identify the current layer in a Razor view something like:
if(layer == "TheHomePage") { ... }
2) Is this the best way to conditionally modify html based on a particular layer?

Dec 13, 2013 at 9:43 PM
There can be multiple layers matched for a request, for example it can be authenticated and also homepage. What is the scenario you want something like this?

Dec 13, 2013 at 11:03 PM
I was wanting to add a css class to a container div if it is the home page. I ended up just matching based on url. I was specifically wanting to match the homepage layer but wasn’t thinking of the multiple layers scenario. Is there a way to get the list of all layers that match the current request?
Dec 14, 2013 at 12:57 AM
I don't know if it's possible to get a list of matching layers.

If it's just home page, url should be ok. If you want something more flexible, you can put some script in an HTML widget, and add the class to the div using jQuery or plain javascript. You can add the widget to a layer. If you feel the need to add it to more than one layer, you can always create a combined layer with and/or operators. Remember to add the widget to the Content zone to keep zone rendering untouched.