Essentially parsing and rendering template proccess is not to handle with echo but handle with API from package html/template. So way render template in echo is same like a real applications used go.
PRACTICE
Ok so to make it easier to understand go to practice right now and create file main.go on your text editor.
First step, we need import package html/template, io, and echo.
Create struct Renderer, this struct have a 3 property and 2 method.
Here`s the assignment and explanation of the third property above.
- Property .template accountable for parsing and rendering template.
- Property .location direct to path folder when file template stand.
- Property .debug relocate type a bool.
Next, create function NewRenderer() for easier inisialitation objek renderer.
Create 2 method for struct Renderer is .ReloadTemplates() and .Render()
Next, create echo router, override property and create a route.
When we call newRenderer() used ./*.html to lead for all html file in current folder. Create index.html
Testing
Finally! Try at home.
Top comments (0)