I would like to keep a specific DocType at the top of the tree that contains it, even after new content is added or the sort order is manually changed.
I am using V6.1.6 - which event(s) would I need to monitor in order to catch anything that may change the position of this DocType (that I want to keep at the top)?
Here is a little snippet I've used in the past to sort home page children:
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Events;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
namespace Site.Events
{
public class HomePageSortEvent : ApplicationEventHandler
{
public HomePageSortEvent()
{
ContentService.Saved += ContentServiceOnSaved;
}
private static void ContentServiceOnSaved(IContentService sender, SaveEventArgs e)
{
var home = e.SavedEntities.First().Parent();
if (home.ContentType.Alias.Equals("HomePage") && home.Children().Any())
{
var children = home.Children();
// Some logic to reorder home page children... For example... children = children.OrderBy(d => d.Name);
sender.Sort(children, raiseEvents: false);
umbraco.BasePages.BasePage.Current.ClientTools.SyncTree(homePage.Path, true);
}
}
}
}
Fix particular DocType at the top in content tree
I would like to keep a specific DocType at the top of the tree that contains it, even after new content is added or the sort order is manually changed.
I am using V6.1.6 - which event(s) would I need to monitor in order to catch anything that may change the position of this DocType (that I want to keep at the top)?
Is this a reasonable solution?
The above is in a function attached to the "ContentService.Saved" event.
Here is a little snippet I've used in the past to sort home page children:
In your case, you'd probably want something like:
is working on a reply...