Templates
The deck is a Go text/template,
evaluated before the Markdown is parsed. Everything the Go template
language has — actions, pipelines, if, range, with, variables — works
in a deck.
Data
The template’s dot holds the front matter’s keys, then the keys of its
data: mapping, then the data given on the command line or in slides.yaml
— each overriding the one before.
---
marp: true
title: Quarterly review
data:
team: Platform
---
# {{ .title }}
Presented by the {{ .team }} team.From the command line:
| Flag | Gives |
|---|---|
--data file.yaml | a YAML or JSON file of data (repeatable) |
--set key=value | one value (repeatable) |
Generating slides
The whole body is one template, so a range that writes --- writes slides:
{{ range .releases }}
---
# {{ .version }}
{{ range .changes }}- {{ . }}
{{ end }}
{{ end }}Page and total
{{ page }} and {{ total }} are the slide’s number and the number of
slides. They are known only once the deck has been split, so they are filled
in then — a generated deck counts the slides it generated.
<!-- footer: "{{ page }} / {{ total }}" -->Include
{{ include "parts/agenda.md" }} inserts another file, relative to the
deck.
Code is left alone
Fenced code blocks and inline code spans are set aside before the template
runs and restored verbatim, so a slide about Go templates can show
{{ .Name }} without escaping it.
Limits
Template execution has a step budget, so that a deck whose templates nest
range over large data lists cannot keep the renderer busy for minutes. Past
1,048,576 steps (loop iterations and template calls, shared with the includes
of one expansion) or 10 s, the deck is refused with the diagnostic
template.limit instead of hanging. A step costs about 260 ns, so ordinary
decks stay far below the bound. Since v0.17.1.
Turning it off
--no-template reads the deck as plain Marp: {{ is text.
Created on by tannevaled
Modified on by tannevaled