Browse Source

go 模板加载

wangshan 4 years ago
parent
commit
38aed7f8be

+ 1 - 1
src/github.com/go-xweb/xweb/action.go

@@ -709,7 +709,7 @@ func (c *Action) Render(tmpl string, params ...*T) error {
 }
 }
 
 
 //仅生成网页内容
 //仅生成网页内容
-var regInclude = regexp.MustCompile(`\{\{\s*include\s*"(.*?\.html)"\}\}`)
+var regInclude = regexp.MustCompile(`\{\{\s*include\s*"(.*?\.html)".*\}\}`)
 
 
 func (c *Action) NamedRender4Cache(name, content string, params ...*T) ([]byte, error) {
 func (c *Action) NamedRender4Cache(name, content string, params ...*T) ([]byte, error) {
 	c.f["oinclude"] = c.Include
 	c.f["oinclude"] = c.Include

+ 3 - 0
src/github.com/go-xweb/xweb/template.go

@@ -365,6 +365,9 @@ func newIncludeIntmpl(rootDir string, content []byte) []byte {
 			b = true
 			b = true
 			tpl := regInclude.FindSubmatch(m)[1]
 			tpl := regInclude.FindSubmatch(m)[1]
 			fpath := filepath.Join(rootDir, string(tpl))
 			fpath := filepath.Join(rootDir, string(tpl))
+			if strings.Contains(string(m), "OUTSIDE") {
+				fpath = string(tpl)
+			}
 			c, err := ioutil.ReadFile(fpath)
 			c, err := ioutil.ReadFile(fpath)
 			if err != nil {
 			if err != nil {
 				return []byte{}
 				return []byte{}