0

how to run range for one time in go template

{{range  . }}
     <a href="/detailed/{{.Namespace}}">
     <p  style="text-align: center;font-size: 2rem;">{{.Namespace}}</p>
{{end}}

I need only first value of Namespace bY using this i am getting more than one values in html

Kalana
  • 5,631
  • 7
  • 30
  • 51
Sai Vamsi
  • 111
  • 3
  • 19

1 Answers1

0

You can use this way

<a href="/detailed/{{ (index . 0).Namespace }}"><p  style="text-align: center;font-size: 2rem;">{{ (index . 0).Namespace }}</p>

Basically, what you want is to get the first element from the range which if you search hard it enough, you can find the answer in another post.

Nguyen Lam Phuc
  • 1,411
  • 1
  • 7
  • 12