Contribute to Docs Contribute to Docs

Hooks

Hooks is a simple way to change, or extend the default behaviour of Piranha CMS. Hooks can either extend the default behaviour or replace a behaviour depending on the hook. Hooks should be added in the Configure method in your application startup after Piranha.App has been initialized.

General

OnGenerateSlug

App.Hooks.OnGenerateSlug += (str) =>
{
    var slug = "";

    // Generate custom slug from input string

    return slug;
}

This hook replaces the default slug generation and can be used when you for example want to support different charsets than the default slug generation. It is executed when a model with a slug (page, post, category & tag) is added and updated.

Alias

The following hooks are available when accessing aliases through the AliasService. All of these hooks can be used to extend the default behaviour of the service layer.

App.Hooks.Alias.RegisterOnLoad((alias) => { ... });

App.Hooks.Alias.RegisterOnBeforeSave((alias) => { ... });
App.Hooks.Alias.RegisterOnAfterSave((alias) => { ... });

App.Hooks.Alias.RegisterOnBeforeDelete((alias) => { ... });
App.Hooks.Alias.RegisterOnAfterDelete((alias) => { ... });

Media

The following hooks are available when accessing media assets through the MediaService. All of these hooks can be used to extend the default behaviour of the service layer.

App.Hooks.Media.RegisterOnLoad((media) => { ... });

App.Hooks.Media.RegisterOnBeforeSave((media) => { ... });
App.Hooks.Media.RegisterOnAfterSave((media) => { ... });

App.Hooks.Media.RegisterOnBeforeDelete((media) => { ... });
App.Hooks.Media.RegisterOnAfterDelete((media) => { ... });

Media Folders

The following hooks are available when accessing folders through the MediaService. All of these hooks can be used to extend the default behaviour of the service layer.

App.Hooks.MediaFolder.RegisterOnLoad((folder) => { ... });

App.Hooks.MediaFolder.RegisterOnBeforeSave((folder) => { ... });
App.Hooks.MediaFolder.RegisterOnAfterSave((folder) => { ... });

App.Hooks.MediaFolder.RegisterOnBeforeDelete((folder) => { ... });
App.Hooks.MediaFolder.RegisterOnAfterDelete((folder) => { ... });

Pages

The following hooks are available when accessing pages through the PageService. Please note that all models are passed in as Piranha.Models.PageBase and must be casted to the applicable type.

App.Hooks.Page.RegisterOnLoad((page) => { ... });

App.Hooks.Page.RegisterOnBeforeSave((page) => { ... });
App.Hooks.Page.RegisterOnAfterSave((page) => { ... });

App.Hooks.Page.RegisterOnBeforeDelete((page) => { ... });
App.Hooks.Page.RegisterOnAfterDelete((page) => { ... });

Params

The following hooks are available when accessing params through the ParamService. All of these hooks can be used to extend the default behaviour of the service layer.

App.Hooks.Param.RegisterOnLoad((param) => { ... });

App.Hooks.Param.RegisterOnBeforeSave((param) => { ... });
App.Hooks.Param.RegisterOnAfterSave((param) => { ... });

App.Hooks.Param.RegisterOnBeforeDelete((param) => { ... });
App.Hooks.Param.RegisterOnAfterDelete((param) => { ... });

Posts

The following hooks are available when accessing posts through the PostService. Please note that all models are passed in as Piranha.Models.PostBase and must be casted to the applicable type.

App.Hooks.Post.RegisterOnLoad((post) => { ... });

App.Hooks.Post.RegisterOnBeforeSave((post) => { ... });
App.Hooks.Post.RegisterOnAfterSave((post) => { ... });

App.Hooks.Post.RegisterOnBeforeDelete((post) => { ... });
App.Hooks.Post.RegisterOnAfterDelete((post) => { ... });

Sites

The following hooks are available when accessing sites through the SiteService. All of these hooks can be used to extend the default behaviour of the service layer.

App.Hooks.Site.RegisterOnLoad((site) => { ... });

App.Hooks.Site.RegisterOnBeforeSave((site) => { ... });
App.Hooks.Site.RegisterOnAfterSave((site) => { ... });

App.Hooks.Site.RegisterOnBeforeDelete((site) => { ... });
App.Hooks.Site.RegisterOnAfterDelete((site) => { ... });

Site Content

The following hooks are available when accessing site content through the SiteService. Please note that all models are passed in as Piranha.Models.SiteContentBase and must be casted to the applicable type.

App.Hooks.SiteContent.RegisterOnLoad((siteContent) => { ... });

App.Hooks.SiteContent.RegisterOnBeforeSave((siteContent) => { ... });
App.Hooks.SiteContent.RegisterOnAfterSave((siteContent) => { ... });

App.Hooks.SiteContent.RegisterOnBeforeDelete((siteContent) => { ... });
App.Hooks.SiteContent.RegisterOnAfterDelete((siteContent) => { ... });