First item in a template range

2/3/2020

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

-- Sai Vamsi
go-templates
kubernetes

1 Answer

2/3/2020

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
Source: StackOverflow