Skip to content
Audrunas edited this page May 14, 2013 · 24 revisions

This documentation page is created to let you understand the way of how to interact with Better CMS - to get data and / or to be notified on particular events.

How to access CMS data?

To catch the main idea how to get some data from the Better CMS, check out the example.

Note: do not forget to wrap API code in using, because context object must be disposed after it was used:

using BetterCms.Core;
using BetterCms.Api;
[...]
using (var context = CmsContext.CreateApiContextOf<PagesApiContext>())
{
	var layouts = context.GetPages();
}
[...]

So, the main idea is to create the API context (for particular module) and to use the methods it provides.

Tip: add references to the modules in App_Data/BetterCMS/Modules folder to access the functionality they provide.

How to get notifications on CMS actions?

If you would like to be notified on some Better CMS actions - let's say when a page is created, check out the bellow:

[...]
using BetterCms.Core; 
using BetterCms.Core.Environment.Host;
using BetterCms.Api;  

public class MvcApplication : HttpApplication
{
    private static ICmsHost cmsHost;
    protected void Application_Start()
    {
        cmsHost = CmsContext.RegisterHost(); 
        AreaRegistration.RegisterAllAreas();

        // Attach to the page creation event.
        PagesApiContext.Events.PageCreated += Events_PageCreated;

        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        cmsHost.OnApplicationStart(this); 
    }

    // Get notified when page is created.
    void Events_PageCreated(SingleItemEventArgs<BetterCms.Module.Pages.Models.PageProperties> args)
    {
        // TODO: do what ever is necessary!
    }
[...]

What events are built in Better CMS?

Events from main modules are described bellow.

  • BetterCms.Module.Root.dll:
    • PageRendering - called each time the page is rendered.
  • BetterCms.Module.Pages.dll - pages / content / widgets related events:
    • CategoryCreated
    • CategoryDeleted
    • CategoryUpdated
    • PageCloned
    • PageContentInserted
    • PageCreated
    • PageDeleted
    • PagePropertiesChanged
    • PagePublishStatusChanged
    • PageSeoStatusChanged
    • RedirectCreated
    • RedirectDeleted
    • RedirectUpdated
    • TagCreated
    • TagDeleted
    • TagUpdated
    • WidgetCreated
    • WidgetDeleted
    • WidgetUpdated
  • BetterCms.Module.Blog.dll - blogs related events:
    • AuthorCreated
    • AuthorDeleted
    • AuthorUpdated
    • BlogCreated
    • BlogDeleted
    • BlogUpdated
  • BetterCms.Module.MediaManager.dll - media related events:
    • MediaFileDeleted
    • MediaFileUpdated
    • MediaFileUploaded
    • MediaFolderCreated
    • MediaFolderDeleted
    • MediaFolderUpdated

Clone this wiki locally