Page Plugin Development
Page plugin is a add-on to Kooboo CMS, and are 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:
- Get data from remote service for users on the Page.
- Submit a Page to add content OR send an email.
- Other requests.
It's OK to write the data access code on the layout OR views, but it's not a recommended in the MVC pattern. A better solution for such cases are to use the Page plug-in to write the logic code into a custom assembly and then upload it Into the Kooboo CMS and use it in Pages or views.
It's 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 is new methods in Kooboo CMS 4.0. They'll is executed corresponding to the HttpMethod (Get and Post).
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 These three files: "AssemblyInitializer.cs", "CustomContentEventSubscriber.cs", " CustomSiteEventsSubscriber.cs ".
- Rename the "Pagepluginsample" as 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 you'll encounter an ' assembly not f Ound "Message at runtime.
- Add the plugin into the Page or View. Note:the execution sequence at runtime would be is the same for your to add the plugin into either Page or View.
The execution sequence of Page plug-in
All the page plug-ins is added both in the page and views (the added in the page, which is not using Renderview.) W Ill is invoked in the controller. The sequence flow for the Page execution would be:kooboo CMS Request flow.jpg
The picture shows the Page plug-ins'll be invoked foremost the controller action.
- when the "Execute" method returns a Not-null ActionResult value, the controller action would b E returned without running the following code. For Example:the plug-in want to return a jsonresult, javascriptresult, Contentresult,fileresult etc ...
- when the "Execute" method returns a Null value, the controller action would continue to run the Foll Owing and render the Page HTML. The developer can store the custom data into ViewData, Which can is used in the Layout and views.
pageViewContext.ControllerContext.Controller.ViewBag.PluginData = "Hello plug-in";
By default, the page plugin'll be invoked in all types of HTTP requests, but can filter by the HTTP method to limit It to run is only on specific types of requests. e.g:
if (pageViewContext.ControllerContext.RequestContext.HttpContext.Request.HttpMethod.ToUpper () = = "POST") { }
Built-in Page Plug-ins
There is three types of Page plug-ins built into Kooboo CMS.
- Addtextcontentplugin, used to add content using the submission values.
- Updatetextcontentplugin, used to update text content using the submission values.
- Deletetextcontentplugin, used to delete text content.
How to write page Plugin in Kooboo-excerpt from official documentation