Implement per-host templates

Fixes #7.

Signed-off-by: Gergely Nagy <me@gergo.csillger.hu>
This commit is contained in:
Gergely Nagy 2025-02-06 17:04:11 +01:00
parent 5be1a9169e
commit 2bdfa92d3e
No known key found for this signature in database
2 changed files with 9 additions and 2 deletions

View file

@ -3,7 +3,9 @@ title: Templating
description: Changing the Iocaine template description: Changing the Iocaine template
--- ---
`iocaine` uses [Handlebars](https://handlebarsjs.com/) for templating, and uses only a single template, `main`. See the Handlebars for basic syntax. A [default template][template:Default] is provided, but if you want to change it, you can configure a [template directory](@/configuration/index.md#templates), and place a customized `main.hbs` file in it, and `iocane` will use that over the default. `iocaine` uses [Handlebars](https://handlebarsjs.com/) for templating, and will look for a template named `hosts/$host.hbs` (where `$host` is whatever is in the hosts header), but fall back on `main`, if a host-specific template is not found.
See the Handlebars for basic syntax. A [default template][template:Default] is provided, but if you want to change it, you can configure a [template directory](@/configuration/index.md#templates), and place a customized `main.hbs` file in it, and `iocane` will use that over the default. Naturally, you can also place host-specific templates in a `hosts/` subdirectory.
[template:default]: https://git.madhouse-project.org/algernon/iocaine/src/branch/main/templates/main.hbs [template:default]: https://git.madhouse-project.org/algernon/iocaine/src/branch/main/templates/main.hbs

View file

@ -144,6 +144,11 @@ impl AssembledStatisticalSequences {
links, links,
}; };
let host_template = &format!("hosts/{}", host);
if handlebars.has_template(host_template) {
handlebars.render(host_template, &data).unwrap()
} else {
handlebars.render("main", &data).unwrap() handlebars.render("main", &data).unwrap()
} }
} }
}