Go-template partials incl. Markdown and nested partials.

Browse this template in the repository →

The PDFs below are rendered live by PDF Server from the shipped examples.

sample

Your browser can’t display this PDF inline.

Download the PDF — go_partials / sample.

go_partials / sample — Download PDF

Inputs

Render data

sample

examples/sample.json

{
  "value": "Example value",
  "items": [
    {"label": "Item 0"},
    {"label": "Item 1"},
    {"label": "Item 2"}
  ]
}

Data schema

schema.json

{
  "type": "object",
  "properties": {
    "value": {
      "type": "string"
    },
    "items": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "label": {
            "type": "string"
          }
        }
      }
    }
  },
  "required": [
    "value"
  ]
}

Template

template.tmpl

<html>
	<body>
		<h1>{{ .value }}</h1>
		{{ template "content" . }}
		{{ template "items" . }}
		{{ template "inner/inner" . }}
		{{ template "footer" . }}
	</body>
</html>

Partials

partials/content.tmpl.md

First paragraph

Second paragraph

1. One point
2. Two point

partials/footer.tmpl

<footer><strong>{{ .value }}</strong></footer>

partials/inner/inner.tmpl

<p>Inner partial</p>

partials/items.tmpl.md

{{ range .items }}
- {{ .label }}
{{ end }}