Template Structure
Gozzi uses Go's standard html/template package for rendering HTML. Your layouts and partials live in the templates/ folder and define how each page or section of your site should look.
Basic Template Organization
templates/
├── home.html # Homepage layout
├── blog.html # Blog section list layout
├── post.html # Blog post (single page)
├── notes.html # Notes list
├── note.html # Single note
├── prose.html # General prose pages
├── tags.html # All tags index
├── tag.html # Posts under a specific tag
├── 404.html # Custom 404 page
├── partials/ # Shared snippets
│ ├── _head.html
│ ├── _header.html
│ ├── _footer.html
│ ├── _scripts.html
│ ├── _toc.html # Table of contents
│ ├── _word_count.html # Reading time
│ ├── _sharing.html # Social sharing
│ ├── _comment.html # Comments section
│ └── _reaction.html # Reaction buttons
└── macros/ # Reusable components
├── alert.html
├── codeblock.html
├── important.html
├── mermaid.html
├── pagination.html
└── warning.htmlTemplate Hierarchy
Templates follow an inheritance pattern:
- Base templates - Define overall structure
- Section templates - Handle list pages
- Page templates - Render individual content
- Partials - Provide reusable components
- Macros - Offer advanced functionality
Template Types
Base Templates
Foundation templates that define site-wide structure:
html
<!-- base.html -->
<!DOCTYPE html>
<html lang="{{ .Site.Config.lang }}">
{{ template "partials/_head.html" . }}
<body>
{{ template "partials/_header.html" . }}
<main>
{{ block "content" . }}
<p>Default content</p>
{{ end }}
</main>
{{ template "partials/_footer.html" . }}
</body>
</html>Section Templates
List pages for content collections (blogs, notes, etc.):
html
<!-- blog.html -->
<!DOCTYPE html>
<html>
{{ template "partials/_head.html" . }}
<body>
<h1>{{ .Section.Config.title }}</h1>
{{ range .Section.Children }}
<article>
<h2><a href="{{ .Permalink }}">{{ .Config.title }}</a></h2>
<time>{{ date .Config.date "Jan 2, 2006" }}</time>
</article>
{{ end }}
</body>
</html>Page Templates
Individual content rendering:
html
<!-- post.html -->
<!DOCTYPE html>
<html>
{{ template "partials/_head.html" . }}
<body>
<article>
<h1>{{ .Page.Config.title }}</h1>
<time>{{ date .Page.Config.date "January 2, 2006" }}</time>
<div class="content">
{{ .Page.Content }}
</div>
</article>
</body>
</html>Directory Organization
Partials Directory
Store reusable components:
templates/partials/
├── _head.html # <head> section
├── _header.html # Site header/navigation
├── _footer.html # Site footer
├── _scripts.html # JavaScript includes
├── _toc.html # Table of contents
├── _word_count.html # Reading time display
└── _sharing.html # Social sharing buttonsNaming convention: Prefix with underscore (_) to indicate partial templates.
Macros Directory
Complex, reusable components:
templates/macros/
├── alert.html # Alert boxes (info, warning, error)
├── codeblock.html # Enhanced code blocks
├── pagination.html # Pagination controls
└── mermaid.html # Mermaid diagram wrapperOutput Directory Structure
After building, your site structure mirrors content organization:
public/
├── index.html # Home page
├── blog/
│ ├── index.html # Blog section list
│ └── my-post/
│ └── index.html # Individual post
├── notes/
│ ├── index.html # Notes section list
│ └── my-note/
│ └── index.html # Individual note
├── tags/
│ ├── index.html # All tags
│ └── go/
│ └── index.html # Posts tagged "go"
├── css/
│ └── main.css # Stylesheets
├── js/
│ └── main.js # JavaScript
└── img/
└── avatar.webp # Images and assetsTemplate Context
Each template receives a context object (.) with data:
.Site- Global site configuration.Section- Section data (for list pages).Page- Page data (for single pages).Toc- Table of contents- Custom data from
[extra]configuration
Including Templates
Basic Inclusion
html
<!-- Include partial with current context -->
{{ template "partials/_head.html" . }}
{{ template "partials/_header.html" . }}
{{ template "partials/_footer.html" . }}With Custom Data
html
<!-- Pass specific data to partial -->
{{ template "partials/_pagination.html" (dict "items" .Section.Children "per_page" 10) }}Best Practices
- Consistent naming - Use clear, descriptive names
- Organize by purpose - Group related templates
- Use partials - Avoid code duplication
- Prefix partials - Use underscore for reusable components
- Document complex logic - Add comments for clarity
- Test all templates - Ensure they work for all content types
- Keep templates focused - One responsibility per template
Common Template Pattern
html
<!DOCTYPE html>
<html lang="{{ .Site.Config.lang }}">
{{ template "partials/_head.html" . }}
<body class="{{ .Section.Name }}">
{{ template "partials/_header.html" . }}
<main>
<!-- Template-specific content -->
</main>
{{ template "partials/_footer.html" . }}
{{ template "partials/_scripts.html" . }}
</body>
</html>Related: