Notifications

Starting with Umbraco v9, the notification pattern is used for events throughout the application. SeoToolkit also comes with some notifications that you are able to hook into to change the data flowing through the package.

GenerateSitemapNodeNotification

This notification is used for each node in the sitemap. You can hook into it to set your own defaults or to remove pages that shouldn't be shown.

public class ExampleSitemapNodeNotification : INotificationHandler<GenerateSitemapNodeNotification>
    {
        public void Handle(GenerateSitemapNodeNotification notification)
        {
            notification.Node.Priority ??= 0.5;
        }
    }

GenerateSitemapNotification

This notification is used when all data for the sitemap has been gathered but before the actual rendering of it. This allows you to add new nodes to the page for dynamic pages.

public class ExampleSitemapNotification : INotificationHandler<GenerateSitemapNotification>
    {
        public void Handle(GenerateSitemapNotification notification)
        {
            notification.Nodes.Add(new SitemapNodeItem("https://google.nl"));
        }
    }

BeforeMetaTagsNotification

This notification is used before the meta fields are generated by the fallback values. If you fill a value here, it'll not use the fallback value of the system.

public class ExampleBeforeMetaTagsNotification : INotificationHandler<BeforeMetaTagsNotification>
    {
        public void Handle(BeforeMetaTagsNotification notification)
        {
            if (notification.ContentTypeAlias.Equals("home"))
            {
                notification.MetaTags.Title = "Hello world!";
                return;
            }
        }
    }

AfterMetaTagsNotification

This notification is used after the meta fields are generated by the fallback values. Here you can extend current values or overwrite them by your own values.

public class ExampleAfterMetaTagsNotification : INotificationHandler<AfterMetaTagsNotification>
    {
        public void Handle(AfterMetaTagsNotification notification)
        {
            notification.MetaTags.Title += "Bye!";
        }
    }

Last updated