Comment by dan353hehe
1 year ago
I love Lua for being able to do things like this.
I was building a bunch of html pages for an htmx frontend and a golang back end, and got really exhausted from using the builtin `html/template` library in golang. I kept trying to build reusable components, and it just didn’t work as I wanted it to.
I ended up doing this exact thing as mentioned in this blog post. https://github.com/DBarney/Glua Granted this is just for me, and for prototyping. I put it on GitHub so I wouldn’t loose it.
Writing html got so much easier this way:
local function Component(data)
return div{"my name is", data.name}
end
return function(params)
html{
head{title="this is my page"},
body{
h1{"This is my small page I wrote"},
p{
"some content",
"more content"
},
div{"page has some dynamic values",params.count},
Component{name="daniel"}
}
}
end
Edit: formatting
you should try https://pkg.go.dev/maragu.dev/gomponents and do it all in go