簡體   English   中英

Gofiber 框架模板的問題

[英]Issue with Gofiber framework template

我正在使用 GO 語言學習 Fiber 框架,並且無法弄清楚為什么當正文部分是 include 時模板引擎返回錯誤。 以下按預期工作,但是當我為“正文部分”添加另一個包含時,它會引發錯誤:

錯誤:

html/template:fun: """ in attribute name: " ">Read Full Article\n "


這個有效:

該模板有效:

我無法在正文內容的中間添加另一個“部分”模板,我什至嘗試了本節中的完整設計 html(不使用包含),無論哪種方式,它在加載時都會拋出相同的錯誤。 出於某種原因,上面的示例主體工作正常,但錯誤並沒有告訴我太多。

這行不通:

這行不通

這也不起作用:

{{template "includes/header" .}}
{{template "includes/navigation" .}}
// full html body text here  (much longer than first working example)
{{template "includes/footer" .}}

我不確定為什么標准模板引擎會出現問題,因為錯誤不是很清楚,但我可以通過切換噴氣引擎來解決問題。 Jet 似乎有更好的錯誤處理。 所有模板擴展名必須切換到 .jet 擴展名,並且包含稍微更改為 {{include "directory/file_name" }}

// Loading Templates
engine := jet.New("./views", ".jet")

// Start Fiber
app := fiber.New(fiber.Config{
    Views: engine,
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM