#Migrate html/templates to Templ
4 messages · Page 1 of 1 (latest)
Yes so I create my LayoutPage and pass {children...} on the body and created a Templ file for my home page like:
templ TemplHomePage() {
@controller.LayoutPage("Home") {
<div class="home-page">
<div class="banner">
<div class="container">
<h1 class="logo-font">conduit</h1>
<p>A place to share your knowledge.</p>
</div>
</div>
</div>
}
}
Im unsure how the CreateLayout function will translate with Templ tho.
I guess what im trying to figure out is:
func (h *Handlers) homePage(w http.ResponseWriter, r *http.Request) error {
data := CreateLayout[HomePage](r, "Home", HomePage{})
return homePageTmpl.Execute(w, data)
}
homePage on the router file is called with h.homePage where with my HomeTemplExample templ file, im not sure if I need to have it on a handler or just import it. I feel there is a better way to do this.
Ok I was being dumb.
func (h *Handlers) homePageTempl(w http.ResponseWriter) error {
return controller.HomeTemplExample().Render(context.Background(), w)
}
package controller
templ LayoutPageTempl() {
<div>Render this</div>
<div id="wrapper">
{children...}
</div>
}
This is all I needed. Working and ready to move on. Sorry @runic geyser