英文:
Issue with Gofiber framework template
问题
我正在学习GO语言中的Fiber框架,并且在解决模板引擎返回错误的问题时遇到了困难。当body部分是一个include时,以下代码可以正常工作,但是当我添加另一个include用于"body section"时,就会抛出错误:
错误信息:
html/template:fun: """"在属性名中:"" ">Read Full Article</a>\n ""
这个可以正常工作:
我无法在body内容中添加另一个"partial"模板,我甚至尝试在这个部分中使用完整的设计HTML(不使用include),但无论哪种方式,加载时都会抛出相同的错误。不知何故,上面的示例body可以正常工作,但错误信息并没有给我提供太多信息。
这个无法工作:
这个也不工作:
{{template "includes/header" .}}
{{template "includes/navigation" .}}
// full html body text here (much longer than first working example)
{{template "includes/footer" .}}
英文:
I am in the process of learning fiber framework in GO language and having trouble figure out why the template engine is returning an error when the body section is an include. The following works as expected but when I add in another include for the "body section" it throws an error:
The Error:
html/template:fun: """ in attribute name: " ">Read Full Article</a>\n "
This one works:
I am unable to add another template "partial" in the middle for body content, I have even tried the full design html in this section (without using includes), either way it throws the same error when loading. For some reason this sample body above works fine, but the error isn't telling me much.
This won't work:
Nor does this work:
{{template "includes/header" .}}
{{template "includes/navigation" .}}
// full html body text here (much longer than first working example)
{{template "includes/footer" .}}
答案1
得分: 0
我不确定为什么标准模板引擎出现问题,因为错误信息不太清楚,但我通过切换到Jet引擎来解决了这个问题。Jet似乎具有更好的错误处理能力。所有模板扩展名必须切换为.jet扩展名,并且包含部分的语法稍有变化,变成{{include "directory/file_name"}}。
// 加载模板
engine := jet.New("./views", ".jet")
// 启动Fiber
app := fiber.New(fiber.Config{
Views: engine,
})
英文:
I am not sure why the standard template engine had issues because the errors were not very clear, but I was able to fix the issue by switching over the jet engine. Jet seems to have better error handling. All template extensions must be switched to .jet extension and the includes change a little bit to {{include "directory/file_name" }}
// Loading Templates
engine := jet.New("./views", ".jet")
// Start Fiber
app := fiber.New(fiber.Config{
Views: engine,
})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论