package optional_test
import (
"html/template"
"log"
"os"
"xengineering.eu/optional-go/optional"
)
func Example_template() {
data := struct {
Flag optional.Optional[bool]
}{
Flag: optional.Optional[bool]{
Value: false,
Exists: false,
},
}
tmpl := `Flag is: {{if .Flag.Exists}}{{.Flag.Value}}{{else}}[none]{{end}}`
t, err := template.New("optional").Parse(tmpl)
if err != nil {
log.Fatal(err)
}
err = t.Execute(os.Stdout, data)
if err != nil {
log.Fatal(err)
}
// Output: Flag is: [none]
}