Add coalescing operator
This commit is contained in:
@@ -34,15 +34,13 @@ func main() {
|
||||
}
|
||||
|
||||
name := r.URL.Query().Get("name")
|
||||
if name == "" {
|
||||
name = "World"
|
||||
vars := map[string]any{"title": "Home"}
|
||||
if name != "" {
|
||||
vars["name"] = name
|
||||
}
|
||||
|
||||
err = tmpl.
|
||||
WithVarMap(map[string]any{
|
||||
"title": "Home",
|
||||
"name": name,
|
||||
}).
|
||||
WithVarMap(vars).
|
||||
Execute(w)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<section class="hero is-fullheight-with-navbar">
|
||||
<div class="hero-body">
|
||||
<div class="container">
|
||||
<p class="title">Hello, #(name)!</p>
|
||||
<p class="title">Hello, #(name | "World")!</p>
|
||||
<p class="subtitle">This is a demo of the Salix template engine.</p>
|
||||
<a class="button is-link is-rounded" href="/about">About →</a>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user