mirror of
https://github.com/kataras/iris.git
synced 2026-01-08 20:41:57 +00:00
Available is never returns false, just re-allocate on .Close - test https://github.com/iris-contrib/tests/blob/master/server_test.go
This commit is contained in:
@@ -123,7 +123,7 @@ func (e *Engine) ExecuteWriter(out io.Writer, name string, binding interface{},
|
||||
isLayout := false
|
||||
|
||||
renderFilename := name
|
||||
if layout != "" && layout != config.NoLayout {
|
||||
if layout != "" {
|
||||
isLayout = true
|
||||
renderFilename = layout // the render becomes the layout, and the name is the partial.
|
||||
}
|
||||
|
||||
@@ -233,7 +233,7 @@ func (s *Engine) runtimeFuncsFor(name string, binding interface{}) {
|
||||
|
||||
// ExecuteWriter executes a templates and write its results to the out writer
|
||||
func (s *Engine) ExecuteWriter(out io.Writer, name string, binding interface{}, layout string) error {
|
||||
if layout != "" && layout != config.NoLayout {
|
||||
if layout != "" {
|
||||
s.layoutFuncsFor(name, binding)
|
||||
name = layout
|
||||
|
||||
|
||||
@@ -148,6 +148,25 @@ func RegisterSharedFuncs(theFuncs map[string]interface{}) {
|
||||
|
||||
}
|
||||
|
||||
func (t *Template) getLayout(ctx context.IContext, passedLayouts []string) string {
|
||||
|
||||
_layout := ""
|
||||
if len(passedLayouts) > 0 {
|
||||
_layout = passedLayouts[0]
|
||||
} else if ctx != nil {
|
||||
if layoutFromCtx := ctx.GetString(config.TemplateLayoutContextKey); layoutFromCtx != "" {
|
||||
_layout = layoutFromCtx
|
||||
}
|
||||
}
|
||||
if _layout == "" && _layout != config.NoLayout {
|
||||
if t.Layout != config.NoLayout { // the config's Layout is disabled if "" , config.NoLayout should be passed only on ctx.Render but for any case check if user set it as config.NoLayout also
|
||||
_layout = t.Layout
|
||||
}
|
||||
}
|
||||
|
||||
return _layout
|
||||
}
|
||||
|
||||
// Render renders a template using the context's writer
|
||||
func (t *Template) Render(ctx context.IContext, name string, binding interface{}, layout ...string) (err error) {
|
||||
|
||||
@@ -163,18 +182,8 @@ func (t *Template) Render(ctx context.IContext, name string, binding interface{}
|
||||
}
|
||||
}
|
||||
|
||||
// I don't like this, something feels wrong
|
||||
_layout := ""
|
||||
if len(layout) > 0 {
|
||||
_layout = layout[0]
|
||||
} else if layoutFromCtx := ctx.GetString(config.TemplateLayoutContextKey); layoutFromCtx != "" {
|
||||
_layout = layoutFromCtx
|
||||
}
|
||||
if _layout == "" {
|
||||
_layout = t.Layout
|
||||
}
|
||||
_layout := t.getLayout(ctx, layout)
|
||||
|
||||
//
|
||||
ctx.GetRequestCtx().Response.Header.Set("Content-Type", t.ContentType)
|
||||
|
||||
var out io.Writer
|
||||
@@ -209,14 +218,7 @@ func (t *Template) RenderString(name string, binding interface{}, layout ...stri
|
||||
}
|
||||
}
|
||||
|
||||
// I don't like this, something feels wrong
|
||||
_layout := ""
|
||||
if len(layout) > 0 {
|
||||
_layout = layout[0]
|
||||
}
|
||||
if _layout == "" {
|
||||
_layout = t.Layout
|
||||
}
|
||||
_layout := t.getLayout(nil, layout)
|
||||
|
||||
out := t.buffer.Get()
|
||||
// if we have problems later consider that -> out.Reset()
|
||||
|
||||
Reference in New Issue
Block a user