Themes and Templates
Theme structure, template contract, and fallback behavior.
Theme is loaded from <theme.dir>/<theme.name>/ in repository root.
Structure
Example from the documentation template (.np/theme/ there). Other templates and custom rules.yaml setups have other page templates.
<theme>/
templates/
layout.html
home.html
page.html
article.html
hub.html
search.html
notfound.html
assets/
styles.css
main.js
favicon.ico
Template selection
layout.htmlis the common wrapper.- Route
/uses home logic. - For pages,
rules.types.<type>.templateis used. - If files are missing, engine falls back to embedded templates/assets.
Data in templates
Most commonly used values:
.Title,.Description,.Canonical,.BaseURL.Page.Type,.Page.Slug,.Page.Title.Body(rendered HTML).Collections(evaluated collections).Meta.Title— the<title>:seo_title, elsetitle.Meta.OpenGraph,.Meta.JSONLD,.Meta.Robots.Meta.Alternates— language versions (.Lang,.URL) for hreflang.Meta.Published— the note'sdateas RFC 3339.FeedURL— the RSS feed address whenfeed.enabledis set.Settings.<key>— settings fromconfig.yamland theSite.md/Interface.mdnotes.FM.<key>— the note's frontmatter.SearchMode(serverorstatic)
Template functions
Besides Go's built-ins:
humanDate value lang— a frontmatter date as «4 марта 2025» forru, «March 4, 2025» otherwise;isoDate value—2025-03-04, for<time datetime>;dict "Key" value …— several values for one{{ template }}call.
<time datetime="{{ isoDate .FM.date }}">{{ humanDate .FM.date "en" }}</time>
{{ template "card.html" (dict "Root" $ "Item" .) }}
Asset serving
- In
serve: assets are available via/assets/*. - In
build: assets are copied todist/assets/*.