Based on Katsuyuki's answer, I created an extension method for WorkContext to convert all active layers into css classes.
using Orchard;
using Orchard.Widgets.Services;
using System.Collections.Generic;
namespace KidsMinistryTeam.Theme.Extensions
{
static public class WorkContextExtensions
{
static public IList<string> GetLayerCssClasses(this WorkContext workContext)
{
var widgetsService = workContext.Resolve<IWidgetsService>();
var ruleManager = workContext.Resolve<IRuleManager>();
var classNames = new List<string>();
foreach (var layer in widgetsService.GetLayers())
{
try
{
if (ruleManager.Matches(layer.LayerRule))
{
classNames.Add(string.Format("{0}-layer", layer.Name.ToLower())); //add any additional class sanitizing logic here
}
}
catch
{
}
}
return classNames;
}
}
}
Then by adding it to Model.Classes in my theme's Layout.cshtml I am now able to style based on active layers.
foreach(string className in WorkContext.GetLayerCssClasses())
{
Model.Classes.Add(className);
}