An open API service indexing awesome lists of open source software.

https://github.com/z3ntl3/recursive-parser

Enhances Go's html/template by enabling recursive parsing of deeply nested view directories.
https://github.com/z3ntl3/recursive-parser

go parse parser template templates templating

Last synced: about 1 year ago
JSON representation

Enhances Go's html/template by enabling recursive parsing of deeply nested view directories.

Awesome Lists containing this project

README

          

# recursive-parser

Extends [html/template](https://pkg.go.dev/html/template) by adding the ability to recursively parse dirs and files that are deeply nested within each other. In contrast to the default parsers: they cannot work with views nested in deep folder hierarchies.

### Usage
```go
// provide your views folder
p := recursive_parser.New(path.Join(cwd, "views"))

// name the root template
temp := template.New("views")

// walk recursively and use temp as root template to build upon
if err := p.Walk(temp); err != nil {
t.Fatal(err)
}

var out bytes.Buffer // where to write

// execute `hello.html`, injecting it with data props and writing output to `out`
if err := temp.ExecuteTemplate(&out, "hello.html", map[string]string{"title": "yolo"}); err != nil {
t.Fatal(err)
}

// flush the output as string
fmt.Printf("executed temp:\n%s\n", out.String())
```