、新建项目
1、新建===web项目===输入项目名称====完成
二、新建html文件
在新建项目中新建html模板
输入文件名称:
三、认识基本格式
联想出基本格式:
四、编辑html文件
运行html,选择浏览器
五、html常用的快捷键
(1)ctrl+n+w web项目创建
(2)ctrl+n+h html文档创建
(3)ctrl+s 保存html页面(页面上如果未保存会显示*号)
(4)ctrl+r html运行
(5)ctrl+z 撤回
(6)!+tab键 联想基本格式
(7)ctrl+/ 注释和取消注释
(8)ctrl+鼠标滚轮, 字体方大和缩小
六、认识标签
(1)H标签(标题标签)
(2)p标签 (段落标签)
(3)img 标签(图片标签)
两种:第一种widows上传图片,第二种:网上图片链接
第一种
img中显示图片
img中引入图片
第二种:网上图片的链接:
(4) 标签(空格)
(5)em 标签表示斜体
(6)i 标签表示斜体
(7)br 表示换行
(8)b 标签表示加粗
(9) strong 标签表示加粗
(10)s 标签(删除线)
(11)u 标签 (下划线)
(12)font 颜色
(13)sub下标
(14)sup上标
们可以使用以下的方式去渲染html
func main() {
router := gin.Default()
router.LoadHTMLGlob("templates/*")
//router.LoadHTMLFiles("templates/template1.html", "templates/template2.html")
router.GET("/index", func(c *gin.Context) {
c.HTML(http.StatusOK, "index.tmpl", gin.H{
"title": "Main website",
})
})
router.Run(":8080")
}
在html中我们可以使用特殊的双花括号来渲染title这个值
<html>
<h1>
{{ .title }}
</h1>
</html>
值得注意的是这种方式并不是gin特有的,而是golang特有的,它还有其他的模板语法。
{{$article := "hello"}}
也可以给变量赋值
{{$article := .ArticleContent}}
{{funcname .arg1 .arg2}}
{{if .condition}}
{{end}}
{{if .condition1}}
{{else if .contition2}}
{{end}}
{{if not .condition}}
{{end}}
{{if and .condition1 .condition2}}
{{end}}
{{if or .condition1 .condition2}}
{{end}}
{{if eq .var1 .var2}}
{{end}}
{{if ne .var1 .var2}}
{{end}}
(less than){{if lt .var1 .var2}}
{{end}}
{{if le .var1 .var2}}
{{end}}
{{if gt .var1 .var2}}
{{end}}
{{if ge .var1 .var2}}
{{end}}
{{range $i, $v := .slice}}
{{end}}
{{template "navbar"}}
*请认真填写需求信息,我们会在24小时内与您取得联系。