我有兩個 html 模板,index.html擴展base.htmlbase.html 是這樣的:{{ define "base" }}<html><head> <meta charget="utf-8"> <title>{{ template "title" . }}</title> <script type="text/javascript" src="https://code.jquery.com/jquery-2.2.0.min.js"></script> <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> <script type="text/javascript" src="/js/isotope.pkgd.min.js"></script> <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css"> <link rel="stylesheet" type="text/css" href="/css/style.css"></head><body> {{ template "index" . }}</body></html>{{ end }}并且index.html:{{ define "title" }}Homepage{{ end }}{{ define "index" }}<div class="wrapper"> <div class="page-content"> <div class="container"> <div class="left"> <img src="../public/images/img_landing_page_mac.png"> </div> <div class="right"> <h2 style="font-size: 33px; letter-spacing: 5px">Organize <br>Modern Knowledge<br> for Mankind</h2> <p style="font-size: 20px;margin-top: 35px;letter-spacing: 4px">Consume, Colect and Revisit <br>Knowledge at Your Fingertips</p> <a href="#" style="margin-top: 80px;display: inline-block;margin-left: -17px"><img src="../public/images/btn_get_chrome.png"></a> </div> </div> </div></div>{{ end }}它應該在使用回調處理程序在瀏覽器上請求路徑時呈現(xiàn):func IndexHandler(w http.ResponseWriter,r *http.Request){ files:=[]string{"base","index"} util.RenderTemplate(w,nil,files...)}啟動服務器后,我在瀏覽器上請求該路徑,但根本沒有渲染任何內容。我錯過了什么?這里好像沒有領悟到繼承我遵循本教程,嘗試使用繼承/擴展來呈現(xiàn)模板:https://elithrar.github.io/article/approximating-html-template-inheritance/
- 1 回答
- 0 關注
- 227 瀏覽
添加回答
舉報
0/150
提交
取消