No.

See https://github.com/golang/go/issues/10608

In Hugo I built a hackish workaround, see http://gohugo.io/extras/scratch/

bep

onsdag 20. juli 2016 20.56.47 UTC+2 skrev Tong Sun følgende:
>
> How to conditionally set go template variables? 
>
> I want the output of the following code 
> https://play.golang.org/p/6e14hS2u1r
>
>
>  {
>  sweaters := Inventory{"", 17}
>  tmpl, err := template.New("test").
>  Parse(`{{$material := "something"}}{{if .Material}} {{$material := 
> .Material}} {{end}}` +
>  "{{.Count}} items are made of {{$material}}.\n")
>  check(err)
>  err = tmpl.Execute(os.Stdout, sweaters)
>  check(err)
>  }
>  {
>  sweaters := Inventory{"wool", 17}
>  tmpl, err := template.New("test").
>  Parse(`{{$material := "something"}}{{if .Material}} {{$material := 
> .Material}} {{end}}` +
>  "{{.Count}} items are made of {{$material}}.\n")
>  check(err)
>  err = tmpl.Execute(os.Stdout, sweaters)
>  check(err)
>  }
>
>
>
> to be 
>
> 17 items are made of something.
> 17 items are made of wool.
>
>
>
> Using the exact same template. Is that possible? 
>
> Thanks
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to