MCPcopy
hub / github.com/caddyserver/caddy / funcImport

Method funcImport

modules/caddyhttp/templates/tplcontext.go:223–238  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
223func (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
240func (c *TemplateContext) executeTemplateInBuffer(tplName string, buf *bytes.Buffer) error {
241 c.NewTemplate(tplName)

Callers 1

TestImportFunction · 0.80

Calls 4

readFileToBufferMethod · 0.95
GetMethod · 0.65
ResetMethod · 0.65
StringMethod · 0.45

Tested by 1

TestImportFunction · 0.64