1 unstable release
new 0.0.1 | Feb 24, 2025 |
---|
#40 in #tera
14KB
182 lines
Tera backend extension for mdbook
This mdbook
backend makes it possible to use
tera templates and expand the capabilities of
your books. It works on top of the default HTML backend.
Installation
Run
$ cargo install mdbook-tera-backend
Usage
Configuring the backend
To enable the backend, simply add [output.tera-backend]
to your book.toml
,
and configure the place where youre templates will live. For instance
theme/templates
:
[output.html] # You must still enable the html backend.
[output.tera-backend]
template_dir = "theme/templates"
Creating templates
Create your template files in the same directory as your book.
<!-- ./theme/templates/hello_world.html -->
<div>
Hello world!
</div>
Using templates in index.hbs
Since the HTML renderer will first render Handlebars templates, we need to tell
it to ignore Tera templates using {{{{raw}}}}
blocks:
{{{{raw}}}}
{% set current_language = ctx.config.book.language %}
<p>Current language: {{ current_language }}</p>
{% include "hello_world.html" %}
{{{{/raw}}}}
Includes names are based on the file name and not the whole file path.
Tera documentation
Find out all you can do with Tera templates here.
Changelog
Please see CHANGELOG for details on the changes in each release.
Contact
For questions or comments, please contact Martin Geisler or Alexandre Senges or start a discussion. We would love to hear from you.
This is not an officially supported Google product.
Dependencies
~14–26MB
~391K SLoC