MCPcopy
hub / github.com/flosch/pongo2 / SetBaseDir

Method SetBaseDir

template_loader.go:70–91  ·  view source on GitHub ↗

SetBaseDir sets the template's base directory. This directory will be used for any relative path in filters, tags and From*-functions to determine your template. See the comment for NewLocalFileSystemLoader as well.

(path string)

Source from the content-addressed store, hash-verified

68// be used for any relative path in filters, tags and From*-functions to determine
69// your template. See the comment for NewLocalFileSystemLoader as well.
70func (fs *LocalFilesystemLoader) SetBaseDir(path string) error {
71 // Make the path absolute
72 if !filepath.IsAbs(path) {
73 abs, err := filepath.Abs(path)
74 if err != nil {
75 return err
76 }
77 path = abs
78 }
79
80 // Check for existence
81 fi, err := os.Stat(path)
82 if err != nil {
83 return err
84 }
85 if !fi.IsDir() {
86 return fmt.Errorf("the given path '%s' is not a directory", path)
87 }
88
89 fs.baseDir = path
90 return nil
91}
92
93// Get reads the path's content from your local filesystem.
94func (fs *LocalFilesystemLoader) Get(path string) (io.Reader, error) {

Callers 2

NewLocalFileSystemLoaderFunction · 0.95
TestBaseDirectoryFunction · 0.80

Calls 1

AbsMethod · 0.65

Tested by 1

TestBaseDirectoryFunction · 0.64