add tip about lang inject

This commit is contained in:
maddalax 2024-09-25 17:03:12 -05:00
parent 553005f3bf
commit bc361d1141
2 changed files with 28 additions and 0 deletions

View file

@ -91,3 +91,15 @@ func MyButton() *h.Element {
}
```
tip: If you are using Jetbrains IDE's, you can write `// language=js` as a comment above the function call (h.EvalJS) and it will automatically give you syntax highlighting on the raw JS.
```go
// language=js
h.EvalJs(`
if(Math.random() > 0.5) {
self.innerHTML = "Success!";
}
`,
),
```

View file

@ -5,6 +5,21 @@ import (
"htmgo-site/pages/base"
)
func Test() *h.Element {
return h.Button(
h.Text("Submit"),
h.OnClick(
// language=js
h.EvalJs(`
if(Math.random() > 0.5) {
self.innerHTML = "Success!";
}
`,
),
),
)
}
func IndexPage(ctx *h.RequestContext) *h.Page {
return h.NewPage(
base.RootPage(h.Div(
@ -29,6 +44,7 @@ func IndexPage(ctx *h.RequestContext) *h.Page {
),
),
),
Test(),
h.Div(
h.Class("border-b border-b-slate-200 h-1"),
h.Div(