{"id":21296864,"url":"https://github.com/reddec/view","last_synced_at":"2025-09-17T19:23:43.022Z","repository":{"id":216621795,"uuid":"741817422","full_name":"reddec/view","owner":"reddec","description":"Type-safe and hierarchical (with layouts) way to load and render Go HTML templates using the standard library","archived":false,"fork":false,"pushed_at":"2024-01-11T08:44:38.000Z","size":5,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-12T10:51:24.395Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/reddec.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2024-01-11T07:08:05.000Z","updated_at":"2024-09-29T17:12:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"377c8579-af38-4fc8-be67-6a081934c5f9","html_url":"https://github.com/reddec/view","commit_stats":null,"previous_names":["reddec/view"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/reddec/view","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reddec%2Fview","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reddec%2Fview/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reddec%2Fview/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reddec%2Fview/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reddec","download_url":"https://codeload.github.com/reddec/view/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reddec%2Fview/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275649461,"owners_count":25503209,"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","status":"online","status_checked_at":"2025-09-17T02:00:09.119Z","response_time":84,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-21T14:30:13.993Z","updated_at":"2025-09-17T19:23:42.890Z","avatar_url":"https://github.com/reddec.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# View [![GoDoc](https://godoc.org/github.com/reddec/view?status.png)](https://godoc.org/github.com/reddec/view)\n\nThe `view` package provides a type-safe and hierarchical (layouts) way to load and render Go HTML templates using the standard library's [`html/template`](https://pkg.go.dev/html/template) package. It supports loading templates from any sources exposed as [`fs.FS`](https://pkg.go.dev/io/fs#FS). The package comes with no external dependencies and is designed for use in web applications.\n\nThis is extremly light library based on gist https://gist.github.com/reddec/312367d75cc03f1ee49bae74c52a6b31 and has zero external dependecies.\n\nKey points:\n\n- **Hierarchical**: The templates are loaded in a hierarchical way, allowing you to have a base layout and extend it with partials or views at different levels. Layouts  defined in each directory as `_layout.gohtml` file and can be extended.\n- **Type-safe**: The package provides a type-safe wrapper around the standard `html/template` library using a custom `View` struct.\n\n\n## [Example](example/)\n\nLayout\n\n```\n├── main.go\n└── views\n    ├── _layout.gohtml\n    ├── index.gohtml\n    └── info\n        ├── _layout.gohtml\n        └── about.gohtml\n```\n\n\nAnd the code\n\n```go\npackage main\n\nimport (\n\t\"embed\"\n\t\"fmt\"\n\t\"net/http\"\n\n\t\"github.com/reddec/view\"\n)\n\n//go:embed all:views\nvar views embed.FS\n\nfunc main() {\n\tindex := view.Must(view.New[string](views, \"views/index.gohtml\"))\n\tabout := view.Must(view.New[string](views, \"views/info/about.gohtml\"))\n\thttp.HandleFunc(\"/\", func(w http.ResponseWriter, r *http.Request) {\n\t\tindex.Render(w, \"the index page\")\n\t})\n\thttp.HandleFunc(\"/info/about\", func(w http.ResponseWriter, r *http.Request) {\n\t\tabout.Render(w, \"made by RedDec\")\n\t})\n\tfmt.Println(\"ready on :8080\")\n\tpanic(http.ListenAndServe(\":8080\", nil))\n}\n```\n\n- note: `all:view` - the `all:` prefix is required in order to include files with underscore in name prefix\n\n## Installation\n\n```bash\ngo get github.com/reddec/view\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freddec%2Fview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freddec%2Fview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freddec%2Fview/lists"}