跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[Go 编程语言] 有没有什么好用的 HTML 模板引擎

发表于

Go 自己的 html/template 有个问题

完整项目中使用多个区块+layout 会导致永远只有有一个生效,或许是我使用姿势有问题

举例说比如

<!-- layout.html -->
{{block "in"}{{end}}
<!-- a.html -->
{{template "layout.html"}}
{{define "in"}}a{{end}}
<!-- b.html -->
{{template "layout.html"}}
{{define "in"}}b{{end}}
package main

//go:embed *.html
var fs embee.FS

func main() {
    t := &template.New("").ParseFS(fs, "*.html")
    // 无论是 a.html 或者是 b.html 永远都是相同的内容
    // 因为所谓的 name 也算 define 内容一次被定义后会被后边的覆盖
    t.ExecuteTemplate(os.Stdout, "a.html", nil)
}

正确的方法应该是我这次需要显示 a.html ,就需要 template.new("").parsefs(fs,"layout.html","a.html")需要 b.html 的时候,再重新 parsefs(fs,"layout.html","b.html")

感觉就很……

要一个项目里几十上百个文件光是这个定义不得写死- -正确的使用姿势是什么呢?

看到 go-pongo2 自己实现了一套 Django 的语法 {% extends "xx" %}

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.