Skip to main content

Pebble extensions

Helpers for building custom Pebble extensions. Register them through InvirtPebbleConfig.extensions.

pebbleFunction

Builds a PebbleFunction from a Kotlin lambda. The lambda receives a PebbleFunctionExecutionContext with the call arguments, current template, evaluation context and line number.

val currentUserFn = pebbleFunction("currentUser") {
request.principal as? User
}

val greetFn = pebbleFunction("greet", "name") {
"Hello, ${args["name"]}"
}

pebbleFunctions

Bundles one or more PebbleFunction instances into an Extension that can be passed to InvirtPebbleConfig.

Invirt.configure(
pebble = InvirtPebbleConfig(
extensions = listOf(
pebbleFunctions(currentUserFn, greetFn)
)
)
)

EvaluationContext.request

Inside a pebbleFunction block, context.request returns the http4k Request for the current render. A pre-built requestFunction and errorsFunction use this internally to expose request() and errors() in macros.