W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
在前面編寫(xiě) Controller 的時(shí)候,我們?cè)?Get 里面寫(xiě)過(guò)這樣的語(yǔ)句 this.TplName = "index.tpl",設(shè)置顯示的模板文件,默認(rèn)支持 tpl 和 html 的后綴名,如果想設(shè)置其他后綴你可以調(diào)用 beego.AddTemplateExt 接口設(shè)置,那么模板如何來(lái)顯示相應(yīng)的數(shù)據(jù)呢?beego 采用了 Go 語(yǔ)言默認(rèn)的模板引擎,所以和 Go 的模板語(yǔ)法一樣,Go 模板的詳細(xì)使用方法請(qǐng)參考《Go Web 編程》模板使用指南
我們看看快速入門(mén)里面的代碼(去掉了 css 樣式):
<!DOCTYPE html>
<html>
<head>
<title>Beego</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<header class="hero-unit" style="background-color:#A9F16C">
<div class="container">
<div class="row">
<div class="hero-text">
<h1>Welcome to Beego!</h1>
<p class="description">
Beego is a simple & powerful Go web framework which is inspired by tornado and sinatra.
<br />
Official website: <a href="http://{{.Website}}" rel="external nofollow" target="_blank" >{{.Website}}</a>
<br />
Contact me: {{.Email}}
</p>
</div>
</div>
</div>
</header>
</body>
</html>
我們?cè)?Controller 里面把數(shù)據(jù)賦值給了 data(map 類型),然后我們?cè)谀0逯芯椭苯油ㄟ^(guò) key 訪問(wèn) .Website 和 .Email 。這樣就做到了數(shù)據(jù)的輸出。接下來(lái)我們講解如何讓靜態(tài)文件輸出。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: