在html/模板中,有什么方法可以在所有页面上拥有恒定的页眉/页脚吗?

问题描述 投票:0回答:2

阅读docs并不是特别有帮助,我想知道结构是否

{{header}}

   {{content that always changes}}

{{footer}}

可以通过golang实现。

go go-html-template
2个回答
2
投票

使用文本/模板

  1. 将其渲染到标准输出的代码

    t := template.Must(template.ParseFiles("main.tmpl", "head.tmpl", "foot.tmpl"))
    t.Execute(os.Stdout, nil)
    
  2. main.tmpl:

    {{template "header" .}}
    <p>main content</p>
    {{template "footer" .}}
    
  3. 脚.tmpl:

    {{define "footer"}}
    <footer>This is the foot</footer>
    {{end}}
    
  4. head.tmpl:

    {{define "header"}}
    <header>This is the head</header>
    {{end}}
    

这将导致:

<header>This is the head</header>
<p>main content</p>
<footer>This is the foot</footer>

使用 html/template 将非常相似。


0
投票

如何查看浏览器?没有终端!

在此输入图片描述

© www.soinside.com 2019 - 2024. All rights reserved.