-
I'm learning templ, go, and htmx currently. Not a lot of resources out there so I'm struggling a lot. Is it possible to do something like this? package web
templ CountResult(newCount string) {
<input id="" name="count" value={ newCount }/>
<span>New Count: { newCount }</span>
<button type="submit">
Increment
</button>
}
templ HelloForm(count string) {
@Base() {
<form hx-post="/hello" method="POST" hx-target="#hello-container">
<input id="name" name="name" type="text"/>
<button type="submit">Submit</button>
</form>
<div id="hello-container"></div>
<form hx-post="/increment" method="POST">
{ CountResult(count) }
</form>
}
}
templ HelloPost(name string) {
<div>Hello, { name }</div>
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Wait! I didn't read the docs enough. Lol, it was just this simple. Found it here: https://templ.guide/syntax-and-usage/template-composition : package web
templ CountResult(newCount string) {
<input id="" name="count" value={ newCount }/>
<span>New Count: { newCount }</span>
<button type="submit">
Increment
</button>
}
templ HelloForm(count string) {
@Base() {
<form hx-post="/hello" method="POST" hx-target="#hello-container">
<input id="name" name="name" type="text"/>
<button type="submit">Submit</button>
</form>
<div id="hello-container"></div>
<form hx-post="/increment" method="POST">
@CountResult(count)
</form>
}
}
templ HelloPost(name string) {
<div>Hello, { name }</div>
} I'm dumm!!!! Anyway... |
Beta Was this translation helpful? Give feedback.
-
Is it possible to have components in different files and still be able to nest them? This is my project structure:
And this is the code: // home.templ
package components
templ Home() {
@Layout() {
<h1>
Hello world!
</h1>
}
}
// components.templ
package components
templ Layout() {
<html>
<head>
<title>My Project</title>
</head>
<body>
<main>
{ children... }
</main>
</body>
</html>
} This causes Layout to not be found.
If I move |
Beta Was this translation helpful? Give feedback.
Wait! I didn't read the docs enough. Lol, it was just this simple. Found it here: https://templ.guide/syntax-and-usage/template-composition :