diff --git a/caddyhttp/httpserver/context.go b/caddyhttp/httpserver/context.go
index 13feedc8a..d7d233c5d 100644
--- a/caddyhttp/httpserver/context.go
+++ b/caddyhttp/httpserver/context.go
@@ -264,8 +264,7 @@ func ContextInclude(filename string, ctx interface{}, fs http.FileSystem) (strin
 		return "", err
 	}
 
-	tpl := template.New(filename).Funcs(TemplateFuncs)
-	tpl, err = tpl.Parse(string(body))
+	tpl, err := template.New(filename).Funcs(TemplateFuncs).Parse(string(body))
 	if err != nil {
 		return "", err
 	}
diff --git a/caddyhttp/httpserver/context_test.go b/caddyhttp/httpserver/context_test.go
index b965e214b..50d9c67ff 100644
--- a/caddyhttp/httpserver/context_test.go
+++ b/caddyhttp/httpserver/context_test.go
@@ -72,8 +72,16 @@ func TestInclude(t *testing.T) {
 			shouldErr:            true,
 			expectedErrorContent: `type httpserver.Context`,
 		},
+		// Test 4 - all good, with custom function
+		{
+			fileContent:          `hello {{ caddy }}`,
+			expectedContent:      "hello caddy",
+			shouldErr:            false,
+			expectedErrorContent: "",
+		},
 	}
 
+	TemplateFuncs["caddy"] = func() string { return "caddy" }
 	for i, test := range tests {
 		testPrefix := getTestPrefix(i)
 
diff --git a/caddyhttp/templates/templates_test.go b/caddyhttp/templates/templates_test.go
index 841cf2027..f190599c3 100644
--- a/caddyhttp/templates/templates_test.go
+++ b/caddyhttp/templates/templates_test.go
@@ -121,6 +121,8 @@ func TestTemplates(t *testing.T) {
 
 	rec = httptest.NewRecorder()
 
+	// register custom function which is used in template
+	httpserver.TemplateFuncs["root"] = func() string { return "root" }
 	tmplroot.ServeHTTP(rec, req)
 
 	if rec.Code != http.StatusOK {
diff --git a/caddyhttp/templates/testdata/root.html b/caddyhttp/templates/testdata/root.html
index e1720e726..ccc1f6349 100644
--- a/caddyhttp/templates/testdata/root.html
+++ b/caddyhttp/templates/testdata/root.html
@@ -1 +1 @@
-<!DOCTYPE html><html><head><title>root</title></head><body>{{.Include "header.html"}}</body></html>
+<!DOCTYPE html><html><head><title>{{ root }}</title></head><body>{{.Include "header.html"}}</body></html>