Hooks

Last Updated: 2019-03-02

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 tags through the AliasRepository in the application Api.

OnLoad

App.Hooks.Alias.RegisterOnLoad((alias) =>
{
// Add your code here
});

The OnLoad hook is called when an alias is loaded from the database before it is put into cache. This means that when a cached alias is retrieved it will contain any changes done in this hook.

OnBeforeSave

App.Hooks.Alias.RegisterOnBeforeSave((alias) =>
{
// Add your code here
});

OnAfterSave

App.Hooks.Alias.RegisterOnAfterSave((alias) =>
{
// Add your code here
});

OnBeforeDelete

App.Hooks.Alias.RegisterOnBeforeDelete((alias) =>
{
// Add your code here
});

OnAfterDelete

App.Hooks.Alias.RegisterOnAfterDelete((alias) =>
{
// Add your code here
});