Skip to content

Instantly share code, notes, and snippets.

@cssquirrel
Created January 23, 2017 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cssquirrel/7670a845a9f1b20f74a3bf3abec3137f to your computer and use it in GitHub Desktop.
Save cssquirrel/7670a845a9f1b20f74a3bf3abec3137f to your computer and use it in GitHub Desktop.
Example of creating a custom section in Umbraco
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Xml;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence;
using Umbraco.Web;
namespace ExamplePackage
{
public class installer : ApplicationEventHandler
{
protected const string ExampleSectionAlias = "example";
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
// Gets a reference to the section if the section is already added
Section section = applicationContext.Services.SectionService.GetByAlias(ExampleSectionAlias);
if (section != null) return;
//Add a custom Section
applicationContext.Services.SectionService.MakeNew("Example", ExampleSectionAlias, "icon-smiley");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment