Skip to content

Commit

Permalink
Add usage documentation to extendplate
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleconroy committed Jul 29, 2017
1 parent 00df356 commit 9ce64c0
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,70 @@
```
dep ensure stackmachine.com/extendplate
```

## Usage

Out sample `templates` directory has three templates in a nested structure.

```
teamplates/
├── base
│   ├── billing.html
│   ├── dashboard.html
└── base.html
```

Let's take a look at the three templates.

```
{{/* base.html */}}
<html>
<head>
<title>Go Web Programming</title>
</head>
<body>
{{ template "content" }}
</body>
</html>
```

```
{{/* billing.html */}}
{{define "content"}}
This is billing
{{end}}
```

```
{{/* dashboard.html */}}
{{define "content"}}
This is the dashboard
{{end}}
```

Extendplate ensures the billing and dashboard template inherit from the base
template, inferring the hierarchy from the folder layout.

```go
package main

import (
"os"

"stackamachine.com/extendplate"
)

func main() {
ts, _ := extendplate.ParseDir("templates", "*.html", nil)
tmpl := ts.Lookup("base/dashboard.html")
tmpl.Execute(os.Stdout, nil)
// <html>
// <head>
// <title>Go Web Programming</title>
// </head>
// <body>
// This is the dashboard
// </body>
// </html>
}
```

0 comments on commit 9ce64c0

Please sign in to comment.