go - Golang templates for web application -
i writing web application in golang, not using framework.
i trying create layout
similar layouts in nodejs, example.
=== layout.html ====
{{ define "layout"}} <!doctype html> <html> <head> <meta charset='utf-8'> <link href="/static/style.css" rel="stylesheet" media="all" type="text/css"> </head> <body> {{ template "content"}} </body> </html> {{ end }}
i have content in home.html
{{ define "content"}} <h1>{{.title}}</h1> <div>this test</div> {{ end }}
i have 2 problems approach
(1) execute template code, not seem passing data content
templates.executetemplate(w, "layout", &page{title: "home", body: nil})
(2) if want have multiple pages same layout, above not work not specify content load.
can please explain strategy using tempates , 'layouts' in golang ?
(2) if want have multiple pages same layout, above not work not specify content load.
you need build matter.
it can template func, knows template, receives block name , args call t.executetemplate, somehow did.
but method has severe drawback, requires every request produces own compiled template.
it can method of view args. can let build template once, re use instance every request, argument change.
no matter what, if keep using built in template
helper can t variable, locked use static string.
Comments
Post a Comment