Created
October 3, 2023 11:42
-
-
Save NoobforAl/f972130a217e40cdff90f279594f20aa to your computer and use it in GitHub Desktop.
Very Simple example templ go PKG
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
package main | |
templ hello(names []string) { | |
<div> | |
for _, name := range names { | |
<div>Hello,{ name }</div> | |
} | |
</div> | |
} |
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
// for start program | |
// intsall templ: go install github.com/a-h/templ/cmd/templ@latest | |
// and go generate | |
// finaly run code : go run *.go | |
//go:generate templ generate | |
package main | |
import ( | |
"fmt" | |
"net/http" | |
"github.com/a-h/templ" | |
) | |
func main() { | |
names := []string{"John", "Atlas", "Farhad"} | |
component := hello(names) | |
http.Handle("/", templ.Handler(component)) | |
fmt.Println("http://localhost:3000") | |
_ = http.ListenAndServe("localhost:3000", nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment