-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tom Brereton
authored and
Tom Brereton
committed
Jan 10, 2024
1 parent
054528a
commit 46ef0bb
Showing
4 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package routes | ||
|
||
import ( | ||
"html/template" | ||
"net/http" | ||
|
||
"github.com/go-chi/chi/v5" | ||
) | ||
|
||
func Htmx(t *template.Template) *chi.Mux { | ||
r := chi.NewRouter() | ||
|
||
r.Get("/", func(w http.ResponseWriter, r *http.Request) { | ||
err := t.ExecuteTemplate(w, "htmx-demo.html", nil) | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
} | ||
}) | ||
|
||
return r | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{{ define "htmx-demo.html" }} | ||
<p class="text-slate-500 text-lg">Who needs SPA</p> | ||
{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,17 @@ | |
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link href="/static/css/styles.css" rel="stylesheet"> | ||
<script src="https://unpkg.com/[email protected]"></script> | ||
</head> | ||
|
||
<body> | ||
<h1 id="hello" class="text-3xl font-bold text-blue-500 underline"> | ||
Hello, {{ .Name }}! | ||
</h1> | ||
<!-- have a button POST a click via AJAX --> | ||
<button hx-get="/clicked" hx-swap="outerHTML" class="m-2 p-2 rounded-lg bg-slate-800 text-white"> | ||
Click Me | ||
</button> | ||
</body> | ||
|
||
</html> | ||
|