funcImport parses the filename into the current template stack. The imported file will be rendered within the current template by calling {{ block }} or {{ template }} from the standard template library. If the imported file has no {{ define }} blocks, the name of the import will be the path
(filename string)
| 221 | // {{ template }} from the standard template library. If the imported file has |
| 222 | // no {{ define }} blocks, the name of the import will be the path |
| 223 | func (c *TemplateContext) funcImport(filename string) (string, error) { |
| 224 | bodyBuf := bufPool.Get().(*bytes.Buffer) |
| 225 | bodyBuf.Reset() |
| 226 | defer bufPool.Put(bodyBuf) |
| 227 | |
| 228 | err := c.readFileToBuffer(filename, bodyBuf) |
| 229 | if err != nil { |
| 230 | return "", err |
| 231 | } |
| 232 | |
| 233 | _, err = c.tpl.Parse(bodyBuf.String()) |
| 234 | if err != nil { |
| 235 | return "", err |
| 236 | } |
| 237 | return "", nil |
| 238 | } |
| 239 | |
| 240 | func (c *TemplateContext) executeTemplateInBuffer(tplName string, buf *bytes.Buffer) error { |
| 241 | c.NewTemplate(tplName) |