Ok, Variable substitution doesn't seem to work in an included template file. Is that a known limitation?
On Saturday, February 3, 2024 at 11:40:40 PM UTC-8 joseph.p...@gmail.com wrote: > I'm goofing around with GIN and trying some examples. I can't get > templating to work for me. > > File inclusion works, but variable substitution does not. > > GOLANG version 1.20.12 > > package main > > > import "github.com/gin-gonic/gin" > > import "net/http" > > // import "gorm.io/driver/sqlite" > > // import "gorm.io/gorm" > > > func main() { > > > server := gin.Default() > > > server.Static("/stylesheets", "./") > > > server.LoadHTMLGlob("templates/*.html") > > > server.GET("/test", func(ctx *gin.Context) { > > ctx.JSON(200, gin.H{ > > "message": "OK!!", > > }) > > }) > > server.GET("/temp", func(ctx *gin.Context) { > > ctx.HTML(http.StatusOK, "index.html", gin.H{ > > "title": "Main website", > > "foo": "bar", > > }) > > }) > > server.GET("/index", func(ctx *gin.Context) { > > ctx.JSON(200, gin.H{ > > "message": "OK!!", > > }) > > }) > > server.Run(":8080") > > } > > Specifically, opening a browser and accessing the /temp endpoint doesn't > change the title or print the text of 'foo' > > templates/header.html: > > <!DOCTYPE html> > > <title>{{.title}}</title> > > <head> > > <link href=" > https://cdn.jsdelivr.net/npm/boot...@5.3.2/dist/css/bootstrap.min.css > <https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css>" > rel="stylesheet" > integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" > > crossorigin="anonymous"> > > </head> > > > <body class="container"> > > > > What's going on here? > > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/897d8172-07e2-42f5-a06d-57885d41fc16n%40googlegroups.com.