Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/imantung/dirtmpl
Go directory based template
https://github.com/imantung/dirtmpl
golang nested-templates
Last synced: 27 days ago
JSON representation
Go directory based template
- Host: GitHub
- URL: https://github.com/imantung/dirtmpl
- Owner: imantung
- License: mit
- Created: 2024-10-12T02:05:51.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-11-11T07:23:52.000Z (about 2 months ago)
- Last Synced: 2024-11-11T08:25:40.713Z (about 2 months ago)
- Topics: golang, nested-templates
- Language: Go
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Go Directory Template
Generate go template map based on the directory.
The conventions are:
- Base template file at `_base/__base.*`
- Components template file at `_private/*` (will not inherit)Use [go standard template](https://pkg.go.dev/html/template), not additional libraries required.
## Features
- [x] Support nested template
- [x] Support OS file system (relative path)
- [x] Support go fsys (go embed)
- [x] Support html/template
- [x] Support text/template
- [ ] Custom base template folder
- [ ] Custom components folder
- [ ] Exclude specific file
- [ ] Filter by file extension## Usages
Get entries using `dirtmpl.Entries()` or `dirtmpl.EntriesFS()`
```go
entries, err := dirtmpl.Entries("samples/simpletxt")
if err != nil {
log.Fatal(err)
}for _, entry := range entries {
fmt.Println(entry.Key, entry.Filenames)
}
```Get templates using `dirtmpl.TextTemplates()`, `dirtmpl.TextTemplatesFS()`, `dirtmpl.HTMLTemplates()`, or `dirtmpl.HTMLTemplatesFS()`
```go
m, err := dirtmpl.TextTemplates("samples/simpletxt")
if err != nil {
log.Fatal(err)
}tmpl, ok := m["section_b/subsection_b1.md"]
if !ok {
log.Fatal("template not found")
}err = tmpl.Execute(os.Stdout, nil)
if err != nil {
log.Fatal(err)
}
```## Examples
- [ ] Generate static html file
- [ ] Web server with go http standard
- [ ] Web server with echo
- [ ] Web server with gofiber## Author