go - Golang template ignore if no match -


I am trying to change a Golgma template, and ignore if the match is not found. Is this possible? Package main import ("bytes" "FMT" text / template) Type person structure {name string age int} type information strat {name {{.name}}

} "P: = person {name:" John ", age: 24} i: = info {name} {{.}} {Name} name:" none ", id: 5} T: = template. "My template") T, _ = T. purse (msg) buf: = new (bytes.buffer) t.exeit (buff, p) fmt.printlon (buff string) buf = new (bytes buffer) T.Excute (buff, i) fmt.println (buf.String ())} < / Pre>

I like

If you want to print only this name, when it is not an empty string:

  "hello { {{If}}} {{.Name}} {{end}} " 

Otherwise, if you want to print something else: "Hello {{IID}}" {{E Nd}} "

- See also for HTML / templates and text / templates.


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -