Skip to content

Template extending for Go's html/template package

License

Notifications You must be signed in to change notification settings

equinox-io/extendplate

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stakmachine/extendplate

GoDoc Build Status

Install

dep ensure github.com/stackmachine/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.

package main

import (
    "os"

    "github.com/stackmachine/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>
}

About

Template extending for Go's html/template package

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 82.4%
  • HTML 17.6%