templating
Skill3 starsChanged 3 months agoMITView on GitHub
Okapi renders HTML through a Renderer. The built-in Template type wraps html/template and loads from a directory, a glob pattern, an embedded FS, or a config struct. Each avoids constructing the *Template yourself: All are also available as OptionFunc where noted (okapi.WithRenderer(...)). okapi.M is shorthand for map[string]any; each key is accessible in the template as {{.title}}. Other HTML helpers on *Context: c.Render returns okapi.ErrNoRenderer when no renderer is configured. The *Okapi struct has no exported fields — always install a…
In this repository20 other files it gives its agents.
- authenticationSkill
- cliSkill
- contextSkill
- dynamic_routesSkill
- error_handlingSkill
- http_clientSkill
- middlewareSkill
- openapiSkill
- overviewSkill
- request_bindingSkill
- responseSkill
- route_definitionSkill
- routingSkill
- sse_streamSkill
- std_compatSkill
- testingSkill
- tls_httpsSkill
- validationSkill
- websocketSkill
- web_spaSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 54
All are also available as OptionFunc where noted (okapi.WithRenderer(...)).
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Okapi Templating & Rendering
Okapi renders HTML through a Renderer. The built-in Template type wraps html/template and loads from a directory, a glob pattern, an embedded FS, or a config struct.
Renderer Interface
type Renderer interface {
Render(w io.Writer, name string, data interface{}, c *Context) error
}
type RendererFunc func(io.Writer, string, interface{}, *Context) error // adapterLoading Templates
// 1. Directory scan (with extension filter)
tmpl, err := okapi.NewTemplateFromDirectory("public/views", ".html", ".tmpl")
o.WithRenderer(tmpl)
// 2. Glob pattern
tmpl, err := okapi.NewTemplateFromFiles("public/views/*.html")
o.WithRenderer(tmpl)
// 3. Embedded FS (recommended for production)
//go:embed views/*
var views embed.FS
tmpl, err := okapi.NewTemplate(views, "views/*.html")
o.WithRenderer(tmpl)
// 4. Config struct (custom funcs, custom FS)
tmpl, err := okapi.NewTemplateWithConfig(okapi.TemplateConfig{
FS: os.DirFS("templates"),
Pattern: "**/*.html",
BaseDir: "templates",
Funcs: template.FuncMap{"upper": strings.ToUpper},
})
o.WithRenderer(tmpl)Shortcuts on *Okapi
Each avoids constructing the *Template yourself:
o.WithDefaultRenderer("public/views/*.html") // from a file pattern
o.WithRendererFromDirectory("public/views", ".html") // from a directory
o.WithRendererFromFS(views, "views/*.html") // from an fs.FS
o.WithRendererConfig(okapi.TemplateConfig{...}) // from a config struct
o.WithRenderer(customRenderer) // any Renderer implementationAll are also available as OptionFunc where noted (okapi.WithRenderer(...)).
TemplateConfig
| Field | Type | Description |
Pattern | string | File pattern (e.g. views/*.html) |
FS | fs.FS | Embedded or custom filesystem |
Funcs | template.FuncMap | Custom template functions |
BaseDir | string | Base directory for templates |
Adding Templates at Runtime
err := tmpl.AddTemplate("banner", "<h1>{{.Title}}</h1>") // from a string
err = tmpl.AddTemplateFile("path/to/template.html") // from a fileRendering in a Handler
o.Get("/", func(c *okapi.Context) error {
return c.Render(http.StatusOK, "home", okapi.M{
"title": "Welcome",
"user": user,
})
})okapi.M is shorthand for map[string]any; each key is accessible in the template as {{.title}}.
Other HTML helpers on *Context:
c.Render(code, name, data) // named template via the configured Renderer
c.HTML(code, file, data) // parse and render a template file directly
c.HTMLView(code, templateStr, data) // render an inline template stringc.Render returns okapi.ErrNoRenderer when no renderer is configured.
Custom Renderer
// Function adapter — light, parses per request
o.WithRenderer(okapi.RendererFunc(func(w io.Writer, name string, data any, c *okapi.Context) error {
tmpl, err := template.ParseFiles("templates/" + name + ".html")
if err != nil {
return err
}
return tmpl.ExecuteTemplate(w, name, data)
}))
// Struct-based — templates parsed once at startup (preferred in production)
type Template struct{ templates *template.Template }
func (t *Template) Render(w io.Writer, name string, data any, c *okapi.Context) error {
return t.templates.ExecuteTemplate(w, name, data)
}
o.WithRenderer(&Template{
templates: template.Must(template.ParseGlob("public/views/*.html")),
})The
*Okapistruct has no exported fields — always install a renderer withWithRenderer(or one of theWithRenderer*helpers), never by assigning to a field.
Content Negotiation Caveat
c.Respond / c.Return (and the HandleIO / HandleO wrappers) pick the format from the request's Accept header: XML, YAML, JSON, or — for text/plain and text/html — plain text via c.String. They do not route through the renderer. To return rendered HTML, call c.Render / c.HTML / c.HTMLView explicitly.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

