// Load HTML files through the engine engine.LoadHTMLGlob("templates/*.html") // Return the template as a response context.HTML(http.StatusOK, "templates/index.html")
// Load HTML files through the engine engine.LoadHTMLGlob("templates/**/*.html") // Return the template as a response context.HTML(http.StatusOK, "templates/admin/index.html")
Loading Static Resources
Route static resources without parsing them
For example, when accessing http://127.0.0.1:8080/static/img.png, the image file is returned directly
Directory Structure
1 2 3
- main.go + static - img.png
Loading Static Resources
Map the request path of static resources to the actual storage path of the static resource file
/static: Request path ./static: Actual storage path of the static resource file
eq: Determines if the values on both sides are equal ne: Determines if the values on both sides are not equal lt: Determines if the value on the left side is less than the value on the right side le: Determines if the value on the left side is less than or equal to the value on the right side gt: Determines if the value on the left side is greater than the value on the right side ge: Determines if the value on the left side is greater than or equal to the value on the right side
// Load HTML files through the engine engine.LoadHTMLGlob("templates/*.html") // Return the template as a response context.HTML(http.StatusOK, "templates/index.html")
Using Custom Template Functions
1
{{TemplateName1 .key}}
Loading Other Templates in Templates
Extract common parts of the template as templates and load other templates in the template