Go templates with eq and index -


go templates have unexpected results when using eq index me. see code:

package main  import (     "os"     "text/template" )  func main() {     const mytemplate = ` {{range $n := .}}     {{index $n 0}} {{if (index $n 0) eq (index $n 1)}}={{else}}!={{end}} {{index $n 1}} {{end}} `     t := template.must(template.new("").parse(mytemplate))      t.execute(os.stdout,         [][2]int{             [2]int{1, 2},             [2]int{2, 2},             [2]int{4, 2},         })  } 

i expect have output

1 != 2 2 = 2 4 != 2 

but

1 = 2 2 = 2 4 = 2 

what should change able compare array members in go templates?

eq prefix operation:

{{if eq (index $n 0) (index $n 1)}}={{else}}!={{end}} 

playground: http://play.golang.org/p/kefxh6s7n1.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -