Created
November 11, 2014 10:44
-
-
Save zhangskills/34e2c489a6d6f62b655b to your computer and use it in GitHub Desktop.
MartiniPongo2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type MartiniPongo2 struct { | |
http.ResponseWriter | |
Context map[string]interface{} | |
} | |
func (m *MartiniPongo2) Html(fileName string, context map[string]interface{}) { | |
for k, v := range context { | |
m.Context[k] = v | |
} | |
var tpl = pongo2.Must(pongo2.FromFile("templates/" + fileName)) | |
err := tpl.ExecuteWriter(m.Context, m.ResponseWriter) | |
if err != nil { | |
panic(err) | |
} | |
} | |
func Render(w http.ResponseWriter, c martini.Context) { | |
martiniPongo2 := &MartiniPongo2{} | |
martiniPongo2.ResponseWriter = w | |
martiniPongo2.Context = make(map[string]interface{}) | |
c.Map(martiniPongo2) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment