12
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[golang]html/templateのテンプレートHTMLでマップ、スライス、配列の指定要素だけ使う記述

12
Last updated at Posted at 2016-05-10

先頭要素だけ使う

{{$var0 := index .Values 0}}
{{$var0}}

要素数の確認を入れたバージョン

+{{$length := len .Values}}
+  {{if ne $length 0}}
  {{$var0 := index .Values 0}}
  {{$var0}}
+{{end}}

全要素をループさせる場合

{{range $var := .Values}}
  {{$var}}
{{end}}

インデックスもつかうなら

{{range $index, $var := .Values}}
  {{$index}}
  {{$var}}
{{end}}

参考

12
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?