Templates

Template function reference for dynamic page content.

Overview

Page content is rendered as a Go template. This means you can use {{...}} syntax to insert dynamic data from your collections, pages, and site settings.

Functions

Query collections, fetch pages, and access site settings with built-in template functions.

Document Methods

Access typed field values from collection records using GetString, GetInt, and more.

Page Methods

Navigate page hierarchy with Path, Parent, Children, and Siblings methods.

Tip

The AI assistant validates templates before saving. If your template has a syntax error, it will catch it and suggest a fix.

Available functions

Functions available in every page template, organized by what they access.

Collection & Document Functions

documents "name"

Returns []Document — All documents in a collection

document "collection" "id"

Returns Document — Single document by collection and ID

collection "name"

Returns Collection — Collection metadata (name, fields)

Page Functions

page "id"

Returns Page — Single page by ID

pages

Returns []Page — All pages

partial "name"

Returns string — Rendered partial template by name

Partial Functions

partials

Returns []string — All available partial template names

Document methods

Documents returned by documents and document have typed accessor methods:

Method Returns Use for
GetString "field" string Text, email, URL, select fields
GetInt "field" int Number fields
GetBool "field" bool Boolean fields
GetTime "field" time.Time Date fields
GetStrings "field" []string JSON array fields (tags, categories)

Page methods

Pages returned by pages and page have navigation methods:

Method Returns Description
Path() string Full URL path (e.g. /about/team)
Parent() Page Parent page (nil if top-level)
Children() []Page Direct child pages
Siblings() []Page Pages at the same level

Examples

Navigation from pages
<nav>
  {{range $p := pages}}
    <a href="{{$p.Path}}">{{$p.Title}}</a>
  {{end}}
</nav>
Blog listing with dates
{{range $post := documents "blog-posts"}}
  <article>
    <h2>{{$post.GetString "title"}}</h2>
    <p>{{$post.GetString "content"}}</p>
    {{with $date := $post.GetTime "publishedAt"}}
      <time>{{$date.Format "Jan 2, 2006"}}</time>
    {{end}}
  </article>
{{else}}
  <p>No posts yet.</p>
{{end}}
Conditional content
{{range $product := documents "products"}}
  {{if $product.GetBool "featured"}}
    <div class="featured">
      <h3>{{$product.GetString "name"}}</h3>
      <span>${{$product.GetInt "price"}}</span>
    </div>
  {{end}}
{{end}}
Include a partial template
<header>
  {{partial "header"}}
</header>
<footer>
  {{partial "footer"}}
</footer>
Child page navigation
{{with $about := page "about-page-id"}}
  <h2>{{$about.Title}}</h2>
  <ul>
    {{range $child := $about.Children}}
      <li><a href="{{$child.Path}}">{{$child.Title}}</a></li>
    {{end}}
  </ul>
{{end}}

Full blog example

A complete blog page using collections and template functions:

<div class="max-w-2xl mx-auto">
  <h1 class="text-4xl font-bold mb-8">Blog</h1>

  {{range $post := documents "blog-posts"}}
    {{if $post.GetBool "published"}}
      <article class="mb-12 pb-12 border-b">
        <h2 class="text-2xl font-bold">
          {{$post.GetString "title"}}
        </h2>
        <div class="text-gray-500 text-sm mt-2">
          By {{$post.GetString "author"}}
          {{with $date := $post.GetTime "publishedAt"}}
            &middot; {{$date.Format "January 2, 2006"}}
          {{end}}
        </div>
        <div class="mt-4 prose">
          {{$post.GetString "content"}}
        </div>
      </article>
    {{end}}
  {{else}}
    <p class="text-gray-500">No posts yet. Check back soon!</p>
  {{end}}
</div>

What's next?