Create views
It´s super easy to create template views and components and further more add your own custom functionality to them.
I don't skip sections of the guide. Please keep in mind that the guide is designed to be read linearly, so try to avoid jumping through it on the first read through.
Create template
You can easily create your own templates if you know some HTML and JavaScript. I will show you a couple of templates below to get you started.
Create a template file named "ingress.js" and add the boilerplate code below to it.
Let's start breaking down the example above. First of all, you will need to create a function that is exported. You can name it whatever you want. The function can utilize four arguments, which I have named: data, container, helper and builder.
The function arguments
data
: This is the object data passed to your template file.container
: The container can be used to communicate with your template and the outside.helper
: Your own possible helper libraries, objects, and functions you passed in the configuration.builder
: Access the Stratox builder library (you can manage without, only for advanced users; more on this later on).
The content
What you place inside the function (component) doesn't actually matter much. Most of the time, you would probably want to create some kind of view, as I have done above. However, you can place function withing the function to which is a recommended way to organize a more advanced component view. You could also for example use it to create a component that will trigger some kind of function. The only thing that sets the boundaries is your creativity. I will show you a little more advance template bellow.
The Return
It is not required to return an output, but if you do, it is expected to return a string value that will automatically be appended to a DOM element if you have specified an element in the Stratox class initialization. If you do not return a value, then your component could handle the appending to DOM part, for example, dynamically append Modals and so on.
Show the template
Now we only need to use the template, as we already discussed on the previous page. It is not harder than this:
The result:
Template table example
Let's create a sortable table template view component.
The are a couple of new things you go through from above table component
eventOnload
This will ensure that the script inside the eventOnload
will execute after the component has been executed.
update
The sort
function will modify the data object feed, then execute inst.update()
function, which will automatically tell Stratox to the component in the DOM element.
Last updated