Creating Static Pages
Static pages (About, Contact, Terms) are simple in Gojang. Steps:
- Create a template in
gojang/views/templates/
that definestitle
andcontent
blocks. - Add a handler method in
gojang/http/handlers/pages.go
that calls the renderer with the template. - Register the route in
gojang/http/routes/pages.go
. - (Optional) Add navigation link in
base.html
.
Example template snippet:
{{define "title"}}About Us{{end}}
{{define "content"}}
<div class="container">
<h1>About Us</h1>
<p>Welcome...</p>
</div>
{{end}}
Handler example:
func (h *PageHandler) About(w http.ResponseWriter, r *http.Request) {
h.Renderer.Render(w, r, "about.html", &renderers.TemplateData{Title: "About Us"})
}
Route registration:
r.Get("/about", handler.About)
Tip: Use HTMX attributes in static pages to add interactive fragments without writing JavaScript.