Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

/p/nym-moultest123/template/v0

Directory · 5 Files
README.md Open

gno.land/p/nym-moultest123/template

A small {{ }} template engine for building Markdown in a realm, with the p/moul/md helpers available as template functions.

1r := template.NewRenderer()
2
3out := r.Render("{{H1 title}}\n\n{{Bold name}} has {{count}} items", map[string]interface{}{
4	"title": "Report",
5	"name":  "moul",
6	"count": 3,
7})

Syntax

form meaning
{{key}} substitute a value from the data map
{{Func arg}} call a template function
{{range items}} ... {{end}} iterate
{{if cond}} ... {{else}} ... {{end}} conditional
{{- x}}, {{x -}} trim whitespace on that side

Whitespace trimming matters more here than in Go's text/template, because the output is Markdown and a stray blank line changes the rendering.

Built-in functions

Markdown, forwarded to p/moul/md: H1 to H6, Bold, Italic, Strikethrough, InlineCode, CodeBlock, LanguageCodeBlock, Blockquote, Paragraph, BulletItem, TodoItem, HorizontalRule, Link, Image, InlineImageWithLink, Footnote, CollapsibleSection, EscapeText.

General: concat, printf, trim, string, index.

Register your own with the Func signature:

1type Func func(args ...string) string

Why not text/template

It is not in the gno standard library, and it would not fit: it reaches for reflection, and template execution has to stay cheap and bounded when it runs inside a Render. This engine is string in, string out, with an explicit function table and no reflection.

Helper is kept as an alias for backward compatibility; new code should use Func.


Part of moul/gno-contracts — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.

Dependency graph:

gno.land/p/nym-moultest123/template/v0 dependency graph

⚠️ Disclaimer: provided as-is, without warranty; not security-audited. Full disclaimer: DISCLAIMER.