Skip to content

Commit

Permalink
Added a Must()-helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
flosch committed Aug 22, 2012
1 parent 1f0eeee commit ee22930
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions template.go
Expand Up @@ -354,6 +354,17 @@ func (tn *tagNode) execute(tpl *Template, ctx *Context) (*string, error) {
//return fmt.Sprintf("<tag='%s'>", tn.content), nil, 1
}

// The Must function is a little helper to create a template instance from string/file.
// It checks whether FromString/FromFile returns an error; if so, it panics.
// If not, it returns the template instance. Is's primarily used like this:
// var tplExample = template.Must(template.FromFile("example.html", nil))
func Must(t *Template, err error) *Template {
if err != nil {
panic(err)
}
return t
}

// Reads a template from file. If there's no templateLocator provided,
// one will be created to search for files in the same directory the template
// file is located. file_path can either be an absolute filepath or a relative one.
Expand Down

0 comments on commit ee22930

Please sign in to comment.