Multiple templates

Learn how to add and use more than one template in your Hi app

There are several reasons that would lead you to create aditional templates. You may need to create a login form or simply have a different template look for specifics views in your app.

Declaring the templates

In hi.xml, add the templates section into the web section.

    <!-- Here we declare the templates of our app-->

When you declare templates, Hi-Framework assumes that all the templates in your app will be declared on that section, so it stops considering the default index template.

The first template to appear in the list is the one that is going to be applied by default.

Changing Templates

The only way to change the your current template is by using a Hi-Framework bean called FrontEnd.

 @Inject FrontEnd frontEnd;

After injecting the FrontEnd bean you will be able to change the current template as shown in the following example:


Changing the template forces Hi-Framework to reload the user's browser in order to apply the new template

Github Repository