Page plugin development

From Kooboo document
Jump to: navigation, search

Intro of Page Plugin

The Page of Kooboo CMS is used to combine the template and content data to render as a regular html page. Generally, it is not a complicated job for the developer, because they do not need to write many codes on the Layout and View. The most frequently used code is the template rendering code. But sometimes, the developer may want to add some complicated logic into more code on the Page, for example:

  • Get data from remote service for users on the Page.
  • Submit a Page to add content OR send email.
  • Other requests.

It is ok to write the code on the layout OR views, while it is not a recommended way in the MVC pattern. A better solution for such case 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 the developers to create the Page Plug-in project 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);

Developing Page Plug-ins

  • Download Kooboo.CMS.PluginTemplate.vsi.
  • Double click the Kooboo.CMS.PluginTemplate.vsi to install the project templates into Visual Studio.
  • Create a Page plug-in project using the project template under "Visual C# -> Web".


  • Remove this three files: "AssemblyInitializer.cs","CustomContentEventSubscriber.cs","CustomSiteEventsSubscriber.cs".
  • Rename the "PagePluginSample" into your own plug-in name.
  • Write the logic code in the "Execute" method.

Using Page Plug-ins

  • Upload assembly of the Page Plug-in into Kooboo CMS Site. NOTE: Please also upload the dependency assemblies of the plugin assembly, otherwise it will throw the exception says assembly not found at runtime.


  • Add the plugin into the Page or View. NOTE: The execution sequence at runtime will be the same for you to add the plugin into either Page or View.


The execution sequence of Page Plug-in

All the Page Plug-ins 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.

  • When the "Execute" method return a NOT-Null ActionResult value, the controller action will be returned without running the following code. For example: The plug-in want to return a JsonResult, JavascriptResult, ContentResult,FileResult etc...
  • When the "Execute" method return a Null value, the controller action will continue to run the following and render the Page html. In this case, the developer can store the custom data into ViewData that can be used in the Layout and Views.
  pageViewContext.ControllerContext.Controller.ViewBag.PluginData = "Hello plug-in";
  • Defautlly, the page plugin will be invoked in all types http request, but you can filter by the http method to limit it only run on the specify type request. e.g:
  if (pageViewContext.ControllerContext.RequestContext.HttpContext.Request.HttpMethod.ToUpper() =="POST")

Build-in Page Plug-ins

There are three types Page Plug-ins build in the Kooboo CMS.

  • AddTextContentPlugin, used to add the a content using the submission values.
  • UpdateTextContentPlugin, used to update a text content using the submission values.
  • DeleteTextContentPlugin, used to delete a text content.