open bi server - Custom HTML Item Plugin
The open bi server is extensible with plugins which are .NET DLLs placed in the OPENBI\httpserver\plugins folder. In this article we are going to explore how to create a plugin for extending the CMS with custom HtmlItems.
HtmlItems are represented as custom HTML tags in the HTML and can be used to output different content depending on the HTML tag attributes or other state. For example: <custom:htmlitem data-template="test">inner HTML</custom:htmlitem>
First create a new .NET library for netstandard2.0 and a references to the open bi server files like OPENBI\ibssolution.bioxRepository.exe. Then add a class which inherits from Ibssolution.biox.Repositoryserver.HtmlItem.
Required methods
Override the GetTagName method which should return a constant and unique string of the HTML tag. The built in HtmlItems are using the openbi:xxx namespace.
Override the GetDescription method which should return a constant string which is used in the HTML editor for documentation.
Override the GetHtmlFromTagChildAsync method which returns the new inner HTML of this HTML Item. Instead of just gernerating the HTML inline it is also possible to use item templates which can be language dependent and are editable in the configurator at runtime. Here are some objects and methods which might be useful:
- cms.HttpContext: provides access to the HTTP request and response.
- cms.OpenBiRequest: provides access to open bi session like the cms.OpenBiRequest.User when logged in.
- HtmlNode.InnerHtml: returns the inner HTML of this node.
- GetItemTemplateAsync: returns the content of an item template depending on the current language.
Optional methods
Override the ProcessActionChildAsync method to accept form POST requests either from JavaScript or standard form POST submissions.
It is best practice to check for custom action types to not interfere with the other HtmlItems.
For example when posting forms always add a <input type="hidden" name="action" value="ACTIONVALUE" />
Unlike in the GetHtmlFromTagChildAsync method it is possible here to access the cms.HttpContext.Response which might be required for returning e.g. JSON.
Override the AddParametersToCollection method to document which parameters (HTML attributes) the HtmlItem can accept.
Override the getReplacementParameters method to document which placeholders are going to be replaced.
For debugging add a custom post build event which automatically copies the DLL to the OPENBI\httpserver\plugins folder. Also use the OPENBI\ibssolution.bioxRepository.exe as starting executable. Because the executable needs to be run as administrator make sure to open the IDE with administrator rights.
It is also possible to reference other NuGet packages as well but make sure that these DLLs are copied directly into the OPENBI folder.
Here is the sample code for creating a plugin which also uses dependency injection to get the ILicense from the open bi server.
Create an item template:
Include the HtmlItem in the page:
And the output will look like this: