template

package module
v0.0.0-...-839a691 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 23, 2017 License: Apache-2.0 Imports: 3 Imported by: 11

README

go-bindata-html-template

GoDoc

go-bindata-html-template is a wrapper for Go's built in html/template package to work with template contents embedded with the go-bindata tool instead of contents on the filesystem See https://github.com/jteeuwen/go-bindata for more information about embedding binary data with go-bindata.

It's compatible with a subset of the functionality in html/template.

Example usage (after running go-bindata data/... in your project directory):

import (
  "github.com/arschles/go-bindata-html-template"
)

//...

func myHandler(res http.ResponseWriter, req *http.Request) {
  tmpl, err := template.New("mytmpl", Asset).Parse("data/templates/my.tmpl")
  if err != nil {
    log.Fatalf("error parsing template: %s", err)
  }
  err := tmpl.Execute(res)
  if err != nil {
    log.Fatalf("error executing template: %s", err)
  }
}

Documentation

Overview

Package template allows standard html/template templates to be rendered from contents embedded with the go-bindata tool instead of the filesystem

See https://github.com/jteeuwen/go-bindata for more information about embedding binary data with go-bindata.

Usage example, after running

$ go-bindata data/...

use:

tmpl, err := template.New("mytmpl", Asset).Parse("data/templates/my.tmpl")
if err != nil {
  log.Fatalf("error parsing template: %s", err)
}
err := tmpl.Execute(os.Stdout)
if err != nil {
  log.Fatalf("error executing template: %s", err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AssetFunc

type AssetFunc func(string) ([]byte, error)

AssetFunc is the function that go-bindata generates to look up a file by name

type FuncMap

type FuncMap template.FuncMap

FuncMap is a convenience type that mirrors the FuncMap type in html/template

type HTML

type HTML string

HTML is another convenience type that mirrors the HTML type in html/template (http://golang.org/src/html/template/content.go?h=HTML#L120)

type Template

type Template struct {
	AssetFunc AssetFunc
	// contains filtered or unexported fields
}

Template is a wrapper around a Template (from html/template). It reads template file contents from a function instead of the filesystem.

func Must

func Must(t *Template, err error) *Template

Must is a helper that wraps a call to a function returning (*Template, error) and panics if the error is non-nil. It is intended for use in variable initializations such as

var t = template.Must(template.New("name").Parse("templates/my.tmpl"))

func New

func New(name string, fn AssetFunc) *Template

New creates a new Template with the given name. It stores the given Asset() function for use later. Example usage:

tmpl := template.New("mytmpl", Asset) //Asset is the function that go-bindata generated for you

func (*Template) Delims

func (t *Template) Delims(left, right string) *Template

Delims is a proxy to the underlying template's Delims function

func (*Template) Execute

func (t *Template) Execute(w io.Writer, data interface{}) error

Execute is a proxy to the underlying template's Execute function

func (*Template) ExecuteTemplate

func (t *Template) ExecuteTemplate(wr io.Writer, name string, data interface{}) error

ExecuteTemplate is a proxy to the underlying template's ExecuteTemplate function

func (*Template) Funcs

func (t *Template) Funcs(funcMap FuncMap) *Template

Funcs is a proxy to the underlying template's Funcs function

func (*Template) Name

func (t *Template) Name() string

Name gets the name that was passed in the New function

func (*Template) Parse

func (t *Template) Parse(filename string) (*Template, error)

Parse looks up the filename in the underlying Asset store, then calls the underlying template's Parse function with the result. returns an error if the file wasn't found or the Parse call failed

func (*Template) ParseFiles

func (t *Template) ParseFiles(filenames ...string) (*Template, error)

ParseFiles looks up all of the filenames in the underlying Asset store, concatenates the file contents together, then calls the underlying template's Parse function with the result. returns an error if any of the files don't exist or the underlying Parse call failed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL