{"id":27693117,"url":"https://github.com/abiosoft/mold","last_synced_at":"2025-10-24T00:35:15.786Z","repository":{"id":283899173,"uuid":"949839276","full_name":"abiosoft/mold","owner":"abiosoft","description":"Higher level use of Go templates for rendering web pages","archived":false,"fork":false,"pushed_at":"2025-03-28T13:52:45.000Z","size":89,"stargazers_count":71,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-03T08:29:36.791Z","etag":null,"topics":["go-template","golang","html","template"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/abiosoft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"abiosoft","custom":["https://buymeacoffee.com/abiosoft"]}},"created_at":"2025-03-17T08:16:48.000Z","updated_at":"2025-03-30T16:41:34.000Z","dependencies_parsed_at":"2025-03-22T22:46:28.431Z","dependency_job_id":null,"html_url":"https://github.com/abiosoft/mold","commit_stats":null,"previous_names":["abiosoft/mold"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abiosoft%2Fmold","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abiosoft%2Fmold/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abiosoft%2Fmold/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abiosoft%2Fmold/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abiosoft","download_url":"https://codeload.github.com/abiosoft/mold/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250822382,"owners_count":21492902,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go-template","golang","html","template"],"created_at":"2025-04-25T12:52:32.993Z","updated_at":"2025-10-24T00:35:10.739Z","avatar_url":"https://github.com/abiosoft.png","language":"Go","funding_links":["https://github.com/sponsors/abiosoft","https://buymeacoffee.com/abiosoft","https://www.buymeacoffee.com/abiosoft"],"categories":[],"sub_categories":[],"readme":"# Mold\n\n[![Build Status](https://github.com/abiosoft/mold/actions/workflows/go.yml/badge.svg)](https://github.com/abiosoft/mold/actions/workflows/go.yml)\n[![Test Coverage](https://codecov.io/gh/abiosoft/mold/graph/badge.svg?token=WS0044G1UZ)](https://codecov.io/gh/abiosoft/mold)\n[![Go Report Card](https://goreportcard.com/badge/github.com/abiosoft/mold)](https://goreportcard.com/report/github.com/abiosoft/mold)\n[![Package Documentation](https://pkg.go.dev/badge/github.com/abiosoft/mold)](https://pkg.go.dev/github.com/abiosoft/mold)\n\nMold builds on [Go templates](https://pkg.go.dev/text/template) to provide a simple and familiar API for rendering web pages.\n\n## Features\n\nMold offers the following, making it an ideal choice for Go projects.\n\n- **Lightweight**: uses only the Go standard library with no external dependencies.\n- **Efficient**: utilises Go's in-built template parser under the hood.\n- **Capable**: supports all capabilities of Go templates.\n- **Familiar**: employs the well-known [concepts](#concepts) of Layouts, Views and Partials.\n\n## Getting Started\n\n### 1. Create a view file\n\nCreate an HTML file named `index.html`.\n\n```html\n{{define \"head\"}}\n\u003clink rel=\"stylesheet\" href=\"https://cdn.simplecss.org/simple.min.css\"\u003e\n{{end}}\n\n\u003ch1\u003eHello from a \u003ca href=\"//github.com/abiosoft/mold\"\u003eMold\u003c/a\u003e template\u003c/h1\u003e\n```\n\n### 2. Render\n\nCreate a new instance and render the view in an HTTP handler.\n\n```go\n//go:embed index.html\nvar dir embed.FS\n\nvar engine, _ = mold.New(dir)\n\nfunc handle(w http.ResponseWriter, r *http.Request){\n    engine.Render(w, \"index.html\", nil)\n}\n```\n\n### Examples\n\nCheck the [examples](https://github.com/abiosoft/mold/tree/main/examples) directory for more.\n\n### Documentation\n\nGo package documentation is available at https://pkg.go.dev/github.com/abiosoft/mold\n\n## Concepts\n\n### Layouts\n\nLayouts provide the overall structure for your web pages.\nThey define the common elements that are shared across multiple views,\nsuch as headers, footers, navigation menus, stylesheets e.t.c.\n\nInside a layout, calling `render` without an argument inserts the view's content into the layout's body.\nTo render a specific section, pass the section's name as an argument.\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n    {{render \"head\"}}\n\u003c/head\u003e\n\u003cbody\u003e\n    {{render}}\n\u003c/body\u003e\n\u003c/html\u003e\n```\nThe [default layout](https://github.com/abiosoft/mold/blob/main/layout.html) can be overridden\nby creating a custom layout file and specifying it as an option for a new instance.\n\n```go\noption := mold.WithLayout(\"path/to/layout.html\")\nengine, err := mold.New(fs, option)\n```\n\n### Views\n\nViews are templates that generate the content that is inserted into the body of layouts.\nTypically what you would put in the `\u003cbody\u003e` of an HTML page.\n\n```html\n\u003ch3\u003eHello from Mold :)\u003c/h3\u003e\n```\n\nThe path to the view file is passed to the rendering engine to produce HTML output.\n\n```go\nengine.Render(w, \"path/to/view.html\", nil)\n```\n\n### Partials\n\nPartials are reusable template snippets that allow you to break down complex views into smaller, manageable components.\nThey are supported in both views and layouts with the `partial` function.\n\nPartials are ideal for sharing common logic across multiple views and layouts.\n\n```html\n{{partial \"path/to/partial.html\"}}\n```\n\nAn optional second argument allows customizing the data passed to the partial.\nBy default, the view's data context is used.\n\n```html\n{{partial \"partials/user_session.html\" .User}}\n```\n\n### Sections\n\nSections allow content to be rendered in specific parts of the layout.\nThey are defined within views with a `define` block.\n\nThe [default layout](https://github.com/abiosoft/mold/blob/main/layout.html) is able to render HTML content within\nthe `\u003chead\u003e` tag by utilising the `head` section.\n\n```html\n{{define \"scripts\"}}\n\u003cscript src=\"//unpkg.com/alpinejs\" defer\u003e\u003c/script\u003e\n{{end}}\n```\n\n\n## Why not standard Go templates?\n\nGo templates, while simple and powerful, can feel unfamiliar when dealing with multiple template files.\n\nMold addresses this by providing an intuitive framework for structuring web applications with Go templates.\n\n## License\n\nMIT\n\n## Sponsoring\n\nYou can support the author by donating on [Github Sponsors](https://github.com/sponsors/abiosoft)\nor [Buy me a coffee](https://www.buymeacoffee.com/abiosoft).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabiosoft%2Fmold","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabiosoft%2Fmold","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabiosoft%2Fmold/lists"}