Accessing parameters from SubLayout

So i’m playing around with Sitecore these days, and i wanted to create a generic navigation rendering that i can reused for both primary and secondary navigation.

One of the issues i ran into was how i can pass settings into my SubLayout, but it turns out it’s actually pretty easy.

Here’s how it’s done when you have a SubLayout based on a Usercontrol.

1
2
3
var sublayout = ((Sitecore.Web.UI.WebControls.Sublayout)this.Parent);  
string rawParameters = sublayout.Parameters;
NameValueCollection parameters = Sitecore.Web.WebUtil.ParseUrlParameters(rawParameters);

Now you can access your parameters via the paramenters collection.

I parsed a css-class to my navigation, and i accesed it like this:

1
2
3
if (parameters["class"] != null) {  
htmlUL.attributes.add("class",parameters["class"].ToString());
}

Comments: