Hello all,
I have just come across a quick, simple & neat way to add a section to your Umbraco website/application be it for your own use or as a package developer.
So rather than talk about it for ages I will just jump straight into it.
public class UmbracoStartup : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
//Get SectionService
var sectionService = applicationContext.Services.SectionService;
//Try & find a section with the alias of "mySection"
var mySection = sectionService.GetSections().SingleOrDefault(x => x.Alias == "mySection");
//If we can't find the section - doesn't exist
if (mySection == null)
{
//So let's create it the section
sectionService.MakeNew("My Section", "mySection ", "icon-users");
}
}
}
So what this is doing on an application startup of Umbraco using the new Section Service checking to see if there a section with the alias of mySection already created, if not then using the section service it goes and creates it.
That’s it, it really is that simple.
Enjoy π