as golang documentation states, template function has have @ least 1 return parameter, think can rule out template functions already.
so thought create function directly on content model, guess not?
i think markup below pretty self explaining (index.tmpl file in root folder):
{{$request := .request}} {{$response := .response}} {{if eq $request.method "post"}} {{.redirect "page1" 301}} {{end}} <!doctype html> <html> <head> <title>{{.title | title}}</title> </head> <body> <h1>{{.title}}</h1> {{.body}} <p>{{.contenttype}}</p> <p>{{$request}}</p> <p>{{lol}}</p> <form method="post"> <input type="text" name="lolcat"/> <input type="submit" value="submit"/> </form> </body> </html> this kinda equivalent how 1 in asp.net/razor, doesn't work.
the rest of code here http://play.golang.org/p/lmkdfla9rs
to test program locally need have:
main.go index.tmpl page1.tmpl (just use same index.tmpl) what doing wrong, , how can achieved? :-)
solution:
http://play.golang.org/p/b2i_uzjish
thanks ainar-g!
logic should go handlers. templates presenting data only. not designed more. decisions , how render should done in handler code.
with in mind, here how that: http://play.golang.org/p/md5a54rlm7.
you can't write directly w because cause set response code 200. should register redirect function inside wrapper because template functions must return 1 or 2 (with error) values. again, because can, doesn't mean should.
Comments
Post a Comment