Home > database >  Issue with Gofiber framework template
Issue with Gofiber framework template

Time:12-31

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\n "


This one works:

This template 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:

This wont 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" .}}

CodePudding user response:

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,
})
  • Related