I went to the beego documentation site, Views -> Template Parsing , the section "Another Aproach", trying to make an example from this section. Created a new project using bee tool. In order not to create a new controller and router has changed the existing default. File controller / default.go:
package controllers import ( "github.com/astaxie/beego" ) type MainController struct { beego.Controller } func (this *MainController) Get() { this.TplName = "blog/add.tpl" this.Data["SomeVar"] = "SomeValue" this.Data["Title"] = "Add" } File views / blog / add.tpl:
{{ template "layout_blog.tpl" . }} {{ define "css" }} <link rel="stylesheet" href="/static/css/current.css"> {{ end}} {{ define "content" }} <h2>{{ .Title }}</h2> <p> This is SomeVar: {{ .SomeVar }}</p> {{ end }} {{ define "js" }} <script src="/static/js/current.js"></script> {{ end}} File views / layout_blog.tpl:
<!DOCTYPE html> <html> <head> <title>Lin Li</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css"> <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap-theme.min.css"> {{ block "css" . }}{{ end }} </head> <body> <div class="container"> {{ block "content" . }}{{ end }} </div> <script type="text/javascript" src="http://code.jquery.com/jquery-2.0.3.min.js"></script> <script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script> {{ block "js" . }}{{ end }} </body> </html> In general, I did everything as indicated in the example, but when I started it, nothing was displayed, it is displayed at intervals of page refresh (you need to refresh the page several times to see the result). The problem in the "{{define}}" and "{{block}}" of the template does not work ... Is it just me or did I do something wrong?
For clarity, recorded a 2 minute video: https://www.screencast.com/t/tjAEAtoT
-raceand see if there are any races. Well, a little advice: it is better to start studying web applications on go from the standard library, and not from the frameworks. - Ainar-G