nonespace
2/23/2020 - 2:12 PM

go_html模板基础语法

{{ $comment_size := len .comments_list }} //获得长度
        {{if  gt $comment_size 0}}   //判断
            <div class="widget d_comment">

                <h3 class="widget_tit">最新评论</h3>
                <ul>
                    {{ range $k,$v := .comments_list}} //遍历
                        <li>
                            <a href="/article/{{$v.ArticleId}}">
                                <img
                                        src="{{$v.AvatarUrl}}"
                                        class="avatar avatar-72" height="50" width="50">{{$v.Name}} <span
                                        class="muted">({{$v.CreatedAt.Format "2006-01-02"}})说://格式化时间
                                <br>
                                {{$v.Content}}</span></a>
                        </li>
                    {{end}}
                </ul>
            </div>
        {{end}}
        
        
        
        
        
        
        
        
  //声明模板
{{define "header"}}

  //使用模板
{{template "header" .}}