Page plugin is an add-on to Kooboo CMS, and is responsible for making data source available for page access. It is similar to module, but while module contains user interface for both the backend and the frontend site, page plugin does not contain any UI. Some of the uses of page plugin are:
It is ok to write the data access code on the layout OR views, but it is not recommended in the MVC pattern. A better solution for such cases is to use the Page Plug-in to write the logic code into a custom assembly, then upload it into Kooboo CMS and use it in Pages or Views.
It is easy to develop a Page Plug-in. We have released the VS Project Template to help developers create Page Plug-in projects more eaisly. The "PagePluginSample.cs" in the project template is the same Page Plug-in. The brief of developing a Page Plug-in is implementing the interface of "IPagePlugin".
public interface IPagePlugin { string Description { get; } ActionResult Execute(Page_Context pageContext, PagePositionContext positionContext);
ActionResult HttpGet(Page_Context context, PagePositionContext positionContext); ActionResult HttpPost(Page_Context context, PagePositionContext positionContext);
} NOTE: The HttpGet and HttpPost are new methods in Kooboo CMS 4.0. They will be executed corresponding to the HttpMethod(Get and Post).
Developing Page Plug-ins
Using Page Plug-ins
The execution sequence of Page Plug-in
All the Page Plug-ins are added both in the Page and Views(The views added in the page, which are not using RenderView.) will be invoked in the controller. The sequence flow for the Page execution will be: Kooboo CMS Request Flow.jpg
The picture shows the Page Plug-ins will be invoked foremost the controller action.
pageViewContext.ControllerContext.Controller.ViewBag.PluginData = "Hello plug-in";
By default, the page plugin will be invoked in all types of http requests, but you can filter by the http method to limit it to run only on specific types of requests. e.g:
if (pageViewContext.ControllerContext.RequestContext.HttpContext.Request.HttpMethod.ToUpper() =="POST") { }
Built-in Page Plug-ins
There are three types of Page Plug-ins built into Kooboo CMS.