Hyper Open Edge Cloud

How To Add A Template

How to Add A Template
  • Last Update:2021-08-31
  • Version:002
  • Language:en


  • Add Template
  • Update Software Profile
  • Update Instance Profile
  • Verification

This how to describe the process of adding a template to be used by a service. To illustrate the process this tutorial adds a index.html file for our html5as service to provide.

Here is the commit introducing this functionality to html5as Software release: commit diff.


Access Theia

You can access the Theia using the url and logging in with username and password.

Create index.html.in Template

Create index.html.in in slapos/software/html5as-base/templates/ directory by right-clicking templates and selecting New File.

Edit index.html.in Template

Open index.html.in and copy the script into it:

{% if title %}
<h1>{{ title }}</h1>
{% endif %}
<p>Hello World</p>

Add [template_index_html] section

Add [template_index_html] section into software.cfg:

recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/${:_update_hash_filename_}
_update_hash_filename_ = templates/index.html.in
md5sum = d57cb01df5941e139b02a2f7bdabcdc8
mode = 0644

Make sure the md5sum is correct by running:

$ cd ~/srv/project/slapos/software/html5as-base/
$ md5sum templates/index.html.in

Add context key in template-cfg

Add context key in [template-cfg]

context =
  key template_index_html_target template_index_html:target

Edit instance.cfg.in

Add link to template

Add it in profile [profile-common] section

template_index_html = {{ template_index_html_target }}

This file is responsible to render the instance file. So it needs to be have the path of the index.html.in template.

Edit instance_html5as.cfg.in

Render template

recipe = plone.recipe.command
command = rm -r ${html5as:docroot}/*; cp ${default_index_html:rendered} ${html5as:docroot}/

recipe = slapos.recipe.template:jinja2
template = {{ parameter_list['template_index_html'] }}
rendered = ${directory:srv}/index.html
context =
  key title slap-parameter:title

A new section is added to render the template. It gets the path of the template by being rendered by instance.cfg.in which got its path from software.cfg.

The template is being rendered with the context key title taken from the parameter title.

Update instance_html5as.cfg.in md5sum

in software.cfg

Run the command:

$ cd ~/srv/project/slapos/software/html5as-base/
$ md5sum instance_html5as.cfg.in

Copy the result in the md5sum key of [instance_html5as] section of software.cfg

Update instance.cfg.in md5sum

in software.cfg

Run the command:

$ cd ~/srv/project/slapos/software/html5as-base/
$ md5sum instance.cfg.in

Copy the result in the md5sum key of [template-cfg] section of software.cfg


  1. Inspect the logs
  2. Verify Index Template
To verify if the template is added, the software is required to re-compile and the instance should be re-instantiated. Then we can access Url provided in connection parameter with curl, the content contains your title in <h1> brackets

Inspect the logs

$ tail -f ~/srv/runner/var/log/slapos-node-software.log
$ tail -f ~/srv/runner/var/log/slapos-node-instance.log

slapos node software and slapos node instance are running automatically every minute at the background. However, you can inspect the logs so that you will be informed that the compiling and instantiating are completed.

Inspect the logs

You can retrieve the logs to inspect.

To retrieve the log of slapos node software, you are supposed to type in the terminal:

$ tail -f ~/srv/runner/var/log/slapos-node-software.log

To retrieve the log of slapos node instance, you are supposed to type in the terminal:

$ tail -f ~/srv/runner/var/log/slapos-node-instance.log

Verify Index Template

Call the request script to capture the connection parameters:

$ cd ~/srv/project/slapos/software/html5as-base/
$ bash ../../../request-html5as-base.sh 

Then you can verify the index template from server_url by

$ curl your_server_url

As long as you see the title parameter passed from the request script on the output of curl, it means the new template is taken into account.