Learn how to modernize your web applications with Kendo UI Builder. We explore custom templates, views, and components for AngularJS and Angular.
Kendo UI Builder 2.0, our latest tool to help you design elegant and responsive web experiences (for both OpenEdge and standalone web apps), introduced the concept of templates, or in other words, the capability to create your own custom views and custom components. The installation bundles several examples that you can tailor. However, these are quite complex and not conducive to learning how to create them from scratch.
This blog is the first of a series where we will explore how to create both custom views and custom components.
We will start with custom views. Since there are quite a few items to understand we will explore the simplest view possible in the form of a “Hello World” custom view. This will help us comprehend the overall mechanics of getting all the elements in place with minimum dependencies and without additional complications. Also, this will constitute a bare-bones working template from which to start writing future templates.
To follow along, download the project zip from github or clone the repository.
Copy the folder “custom-hello-world-v1” to the folder “template/views” in your target application and restart Kendo UI Builder. Click “Add View,” and you should now see the custom Hello World V1 view like in this screenshot:
Select “Custom Hello World V1,” enter view name and label.
Change the title and greeting properties as desired and click Preview. This gives you a feel for the design part and the runtime part. Now, we are ready to explore the project.
When building a custom view or component, there are three main items to construct:
Here is a screenshot illustrating where some of these items show:
Open the file custom-hello-world-v1.json.
This file contains a set of fields. The key fields to define are:
Notes:
These are in the sub-directory “design-time.” In this directory we have:
EJS files are template files. They are executed by Kendo UI Builder to replace the template tags with their actual value. See http://ejs.co/ for more information.
When you program a custom view, you simply provide a representation of the widget that comes close to the runtime view, but you do not have to implement user interactions as Kendo UI Builder does not pass mouse or keyboard events to the design-time view.
The intent is to let you focus your time and energy on the runtime view.
The sub-directory “generator” contains a file called index.js. This file will be executed with node. It contains an entry point called augmentModel. In a future post we will look into an example where we extend the model, but for now we do not need to program anything in this function.
The content of the runtime files will depend on which target framework is used. In Kendo UI Builder 2.x, we support the AngularJS framework. Starting in version 3, we will support both the AngularJS and Angular 5 frameworks.
Note: Kendo UI Builder 3.0 should be available towards the end of May 2018.
For AngularJS: The files are in sub-directory “angularjs”:
Options.json.ejs: This is where we define which view properties will get added to the model in the controller.
The model is added to the variable vm.$model (the view model) in the controller (See controller.js.ejs).
template.html.ejs: This is the file that contains the HTML that will be rendered at runtime. The items defined in options.json.ejs are available from the model.
In this template we can use AngularJS expressions, for example, {{vm.$model.greeting}} to access the “greeting” property.
A property travels from the definition file to the options.json file, then to the controller and finally to the runtime view. To help understand and follow how it travels from each file, I have named the title property:
Note: do not get confused with “title”, which is the label of the field in the view property panel.
Generator/index.js: this file is invoked when generating the source code for the view. Like at design-time, this is where we can augment the model. But we can also provide translations for distinct items using the function getTranslation. In this function, we just return an object literal with the set of items to include in the translation file.
For Angular: The files are in sub-directory “angular”
At this stage, you should be able to add your own property. In the next blog post, we will explore what goes on behind the scenes to complete our understanding.
Read the Next Post
Thierry Ciot is a Software Architect on the Corticon Business Rule Management System. Ciot has gained broad experience in the development of products ranging from development tools to production monitoring systems. He is now focusing on bringing Business Rule Management to Javascript and in particular to the serverless world where Corticon will shine. He holds two patents in the memory management space.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.
Learn MoreSubscribe to get all the news, info and tutorials you need to build better business apps and sites