HTML模板在Golang上的使用 [英] Html template use on golang

查看:604
本文介绍了HTML模板在Golang上的使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,我是初学者,我读过golang.docs,但听不懂. 我:index.html:

Sorry im beginner and i read golang.docs but didnt understand well. i`ve : index.html:

<html>
<head>
</head>
<body>
<form action type="checkbox" name="test" value="A" {{.checked}}>
<input type="submit" value="save">
</body>
</html>

在main.go中 如果用户单击保存"按钮,则选中复选框将页面重定向并显示选中的复选框

in main.go if user click save button then check checkbox redirect that page and show checkbox checked

推荐答案

您可以在map中发送变量.例如:

You could send variables in map. For example:

package main

import (
    "bytes"
    "fmt"
    "text/template"
)

func main() {
    t, _ := template.New("hi").Parse("Hi {{.name}}")
    var doc bytes.Buffer
    t.Execute(&doc, map[string]string{"name": "Peter"})
    fmt.Println(doc.String()) //Hi Peter
}

这篇关于HTML模板在Golang上的使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆