From 56a9fba34daf75797c5fd3a0f6b65000ed3e26fc Mon Sep 17 00:00:00 2001
From: Makis Maropoulos <makis@ideopod.com>
Date: Thu, 2 Jun 2016 18:27:35 +0300
Subject: [PATCH] https://github.com/kataras/iris/issues/167

---
 config/render.go |  6 +++---
 iris.go          | 10 ++++++++++
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/config/render.go b/config/render.go
index 3e9d1651..8037f3d3 100644
--- a/config/render.go
+++ b/config/render.go
@@ -125,12 +125,12 @@ type (
 		// Right delimeter, default is }}
 		Right string
 		// Funcs like html/template
-		Funcs template.FuncMap
+		Funcs map[string]interface{}
 		// Funcs like html/template
 		// the difference from Funcs is that these funcs
 		// can be used inside a layout and can override the predefined (yield,partial...) or add more custom funcs
 		// these can override the Funcs inside no-layout templates also, use it when you know what you're doing
-		LayoutFuncs template.FuncMap
+		LayoutFuncs map[string]interface{}
 	}
 	// Pongo the configs for PongoEngine
 	Pongo struct {
@@ -207,7 +207,7 @@ func DefaultTemplate() Template {
 		ContentType:   "text/html",
 		Charset:       "UTF-8",
 		Layout:        "", // currently this is the only config which not working for pongo2 yet but I will find a way
-		HTMLTemplate:  HTMLTemplate{Left: "{{", Right: "}}", Funcs: template.FuncMap{}, LayoutFuncs: template.FuncMap{}},
+		HTMLTemplate:  HTMLTemplate{Left: "{{", Right: "}}", Funcs: make(map[string]interface{}, 0), LayoutFuncs: make(map[string]interface{}, 0)},
 		Pongo:         Pongo{Filters: make(map[string]pongo2.FilterFunction, 0), Globals: make(map[string]interface{}, 0)},
 		Markdown:      Markdown{Sanitize: false},
 		Amber:         Amber{Funcs: template.FuncMap{}},
diff --git a/iris.go b/iris.go
index 24e044e6..bb7dc523 100644
--- a/iris.go
+++ b/iris.go
@@ -134,6 +134,16 @@ func (s *Iris) initTemplates() {
 					return "", nil
 				},
 			}
+			// these should be already a non-nil map but if .New(cfg) it's not, is mergo's bug, temporary:
+			if s.config.Render.Template.HTMLTemplate.LayoutFuncs == nil {
+				s.config.Render.Template.HTMLTemplate.LayoutFuncs = make(map[string]interface{}, 1)
+			}
+
+			if s.config.Render.Template.HTMLTemplate.Funcs == nil {
+				s.config.Render.Template.HTMLTemplate.Funcs = make(map[string]interface{}, 1)
+			}
+			//
+
 			for k, v := range funcs {
 				// we don't want to override the user's LayoutFuncs, user should be able to override anything.
 				if s.config.Render.Template.HTMLTemplate.LayoutFuncs[k] == nil {