I have been working with Umbraco, the open source CMS (content management system) in .Net, for quite some time. Though it is a good system with many features, the documentation available on the web is not sufficient enough to help the developers with their 'how to' questions. So, I think the help should be provided by sharing the knowledge. With that in mind, I like to include useful umbraco tips within my blog, starting from this post.
There can be many situations where one would want to catch the default events and to implement custom action handlers. One of the important events in a CMS is the 'Publish' event and I have provided here the code to implement a custom action handler.
It is used to make the navigation menu (drop down or what ever) on a web site to be dynamic so that it can be automatically updated without the developer intervention. Usually an editor who adds or removes pages from a site would see this feature a really useful one in CMS enabled site. Here the technic is that, when the home page of the site is published, it automatically updates the javascript which is used for the navigation menu.
The steps to follow;
- Create a visual studio project to build an application library
- Create a class and add the following code
- Change the code according to your requirements
- Build the solution
- Place the built dll file into the umbraco installation's 'bin' folder
- Verify the action form the umbraco management site
Code fragment
public class MenuHandler : umbraco.BusinessLogic.Actions.IActionHandler
{
String umbraco.BusinessLogic.Actions.IActionHandler.HandlerName()
{
// return the name of the custom action handler
return "lib.MenuHandler";
}
umbraco.interfaces.IAction[] umbraco.BusinessLogic.Actions.IActionHandler.ReturnActions()
{
// return the actions for which this action handler is used
return new IAction[] { new ActionPublish() };
}
Boolean umbraco.BusinessLogic.Actions.IActionHandler.Execute(
umbraco.cms.businesslogic.web.Document documentObject, umbraco.interfaces.IAction action)
{
// if more than one actions are returned in ReturnActions() method,
// the action parameter can be used to decide the current action.
// check whether it is the home page which has been published
if (documentObject.ContentType.Alias.Equals("HomePage"))
{
// Code to rebuild the navigation menu
}
}
}



