Skip to content

Templating ​

n5i renders app files with the Tera template engine, whose syntax is similar to Jinja2. Use templates to generate passwords, react to user settings, or include data from other apps and plugins.

Template files ​

FileRenderedContext
app.yml.jinjawhenever the app is loaded, installed or updatedfull context
custom.yml.jinjalike app.yml.jinjafull context
metadata.yml.jinjawhenever the app's metadata is loadedbasic context only
data/**/*.n5i_jinjaon installation and updates, see preloading filesfull context

If both app.yml and app.yml.jinja exist, the template is used.

yaml
# app.yml.jinja
version: 1

containers:
  main:
    image: linkstackorg/linkstack:latest
    ingress_port: 80
    environment:
      SERVER_ADMIN: "{{ settings.admin_email | default(value='admin@example.com') }}"
      APP_KEY: "base64:{{ derive_entropy(identifier='app-key') | hex_to_base64 }}"
{% if "other-app" in installed_apps %}
      OTHER_APP_URL: http://api.other-app.{{ user }}.n5i:3000
{% endif %}

Template context ​

The basic context is available in all templates:

VariableDescription
app_idID of the app.
userID of the user the app is installed for.
user_display_nameDisplay name of that user.
installed_appsIDs of the apps the user has installed.
server_ipIP address of the node.
server_is_publictrue if server_ip is a public IP address.
jwt_pubkey_base64Public key to verify n5i's JWTs.
init_domainDeprecated: the app's primary domain, or a placeholder. Use primary_domain.

The full context also contains:

VariableDescription
settingsThe app's settings, with defaults for settings the user didn't change.
primary_domainThe app's primary domain, if it has one.
pluginsData from context plugins, as plugins.<plugin app>.<plugin id>.

Built-in functions ​

FunctionDescription
derive_entropy(identifier="...")A secret hex string derived from the server's seed, the user, the app and identifier. It is stable across reinstalls and updates, so use it for passwords and keys.
n5i_has_feature(feature="...")Whether this n5i version supports a feature. Currently known: volume-types, disable-network-policy.

Tera's get_env function is disabled.

Built-in filters ​

In addition to Tera's filters:

FilterDescription
sha256SHA-256 hash, hex-encoded.
bcrypt(cost=12)bcrypt hash. cost must be between 4 and 15.
base64_encode, base64_decodeBase64 encoding of a string.
hex_encode, hex_decodeHex encoding of a string.
hex_to_base64, base64_to_hexConvert between hex and base64.

You can add your own functions in JavaScript, see extending the preprocessor.

Preloading files into volumes ​

Files in data/<volume-id>/ are copied into the volume <volume-id> when the app is installed. Files ending in .n5i_jinja are rendered first and saved without that extension, for example data/config/config.yml.n5i_jinja becomes config.yml in volume config. Files ending in .n5i_jinja_hex must render to hex, which is decoded into a binary file.

Free and open-source software under the GNU AGPL 3.0 or later.