Html/template Delims


#1

Hello,

Can I change the “html / template” delimiter?

I tried to do something like that, but it does not work.

func (t *TemplateRenderer) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
	t.templates.Delims("[[", "]]")

	// Add global methods if data is a map
	if viewContext, isMap := data.(map[string]interface{}); isMap {
		viewContext["reverse"] = c.Echo().Reverse
	}

	return t.templates.ExecuteTemplate(w, name, data)
}

Thank you!
Marcelo


#2

@suporte What error are you getting?


#3

No error, just does not respect the configuration.


#4

@suporte I don’t think we do anything special for the templates in the framework. Can you try it without the framework?


#5

https://golang.org/pkg/html/template/#Template.Delims - I quote

“Delims sets the action delimiters to the specified strings, to be used in subsequent calls to Parse, ParseFiles, or ParseGlob.”

In the example above, Delims() is called right before executing the template, but after it was parsed, which is why it is ignored.