mustache — API Reference
Mustache template rendering for Donna
mustache
Mustache template rendering for Donna.
This package binds the C mustach library.
The simple API accepts string key-value pairs. The structured API adds
object-like values and list sections for templates such as {{#posts}}.
Types
pub type ValueStructured template value.
Use text, bool, and list helpers to build values without depending on
the internal wire format used by the C FFI.
mustache.render_view("{{#posts}}{{title}}{{/posts}}", [
mustache.list("posts", [
[mustache.text("title", "Hello")]
])
])
Text(name: String, value: String)Bool(name: String, value: Bool)List(name: String, rows: List(List(Value)))Functions
pub fn text(name: String, value: String) -> ValueCreate a string template value.
pub fn bool(name: String, value: Bool) -> ValueCreate a boolean template value.
pub fn list(name: String, rows: List(List(Value))) -> ValueCreate a repeated list section.
Each row is a list of values that becomes the context for one iteration.
pub fn render(template: String, values: List(#(String, String))) -> StringRender a Mustache template with string key-value data.
import mustache
pub fn greeting() -> String:
mustache.render("Hello {{name}}", [#("name", "Donna")])
pub fn render_with_partials(template: String, values: List(#(String, String)), partials: List(#(String, String))) -> StringRender a Mustache template with string key-value data and partials.
mustache.render_with_partials(
"{{> header}}{{body}}",
[#("body", "Hello")],
[#("header", "<h1>{{title}}</h1>")]
)
pub fn render_view(template: String, values: List(Value)) -> StringRender a Mustache template with structured values.
This supports normal variables, truthy/falsey sections, and list sections.
pub fn render_view_with_partials(template: String, values: List(Value), partials: List(#(String, String))) -> StringRender a Mustache template with structured values and partials.