Grouping your Site Settings in Orchard

I'm slightly OCD when it comes to organising my settings in Orchard, of which I seem to have a vast amount. And luckily, Orchard has a nifty way of doing this for you and it is beautifully simple to implement.

So to start with you are going to need to have some site settings, which I have covered in this post. Once you have built your site setting, you are going to need to create a menu item that will be displayed in an expandable list under the Settings menu item in the Orchard dashboard, which will be done in the handler.

public class UniTownSiteSettingsPartHandler : ContentHandler
 public UniTownSiteSettingsPartHandler(IRepository<UniTownSiteSettingsPartRecord> repository)
  Filters.Add(new ActivatingFilter<UniTownSiteSettingsPart>("Site"));

  T = NullLocalizer.Instance;

 public Localizer T { get; set; }

 protected override void GetItemMetadata(GetContentItemMetadataContext context)
  if (context.ContentItem.ContentType != "Site")
  context.Metadata.EditorGroupInfo.Add(new GroupInfo(T("Statistics")));

The important method here is GetItemMetadata, which I have used to add a new group "Statistics. Next you need to actually place your site settings into that group via the Editor method in your driver.

protected override DriverResult Editor(UniTownSiteSettingsPart part, dynamic shapeHelper)
 return ContentShape("Parts_UniTownSiteSettingsPart",
  () => shapeHelper.EditorTemplate(TemplateName: TemplateName,
   Model: part,
   Prefix: Prefix))

So all we are doing is appending .OnGroup("Statistics") to our return statement. Simple!