Handlebars creates and returns a new handlebars view engine. The given "extension" MUST begin with a dot. Usage: Handlebars("./views", ".html") or Handlebars(iris.Dir("./views"), ".html") or Handlebars(embed.FS, ".html") or Handlebars(AssetFile(), ".html") for embedded data.
(fs interface{}, extension string)
| 45 | // Handlebars(iris.Dir("./views"), ".html") or |
| 46 | // Handlebars(embed.FS, ".html") or Handlebars(AssetFile(), ".html") for embedded data. |
| 47 | func Handlebars(fs interface{}, extension string) *HandlebarsEngine { |
| 48 | s := &HandlebarsEngine{ |
| 49 | fs: getFS(fs), |
| 50 | rootDir: "/", |
| 51 | extension: extension, |
| 52 | templateCache: make(map[string]*raymond.Template), |
| 53 | funcs: make(template.FuncMap), // global |
| 54 | } |
| 55 | |
| 56 | // register the render helper here |
| 57 | raymond.RegisterHelper("render", func(partial string, binding interface{}) raymond.SafeString { |
| 58 | contents, err := s.executeTemplateBuf(partial, binding) |
| 59 | if err != nil { |
| 60 | return raymond.SafeString("template with name: " + partial + " couldn't not be found.") |
| 61 | } |
| 62 | return raymond.SafeString(contents) |
| 63 | }) |
| 64 | |
| 65 | return s |
| 66 | } |
| 67 | |
| 68 | // RootDir sets the directory to be used as a starting point |
| 69 | // to load templates from the provided file system. |
nothing calls this directly
no test coverage detected
searching dependent graphs…