-
Notifications
You must be signed in to change notification settings - Fork 148
API for Developers
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.
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.
To save multiple API calls within one transaction, TransactionScope can be used (System.Transactions must be referenced):
using (var pagesApi = CmsContext.CreateApiContextOf<PagesApiContext>())
{
using (var transaction = new System.Transactions.TransactionScope())
{
pagesApi.CreateLayout(/* parameters */);
pagesApi.CreateLayoutRegion(/* parameters */);
pagesApi.CreateHtmlContentWidget(/* parameters */);
transaction.Complete();
}
}
Tip: add references to the modules in App_Data/BetterCMS/Modules folder to access the functionality they provide.
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!
}
[...]
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