<p>I need to reduce my 'if else code' in my helm chart template<br />
How can I do that ?.</p>
<pre><code>  {{- if .Values.global }}
    {{- if .Values.global.namespace }}
      namespace: {{ .Values.global.namespace }}
    {{- else }}
      namespace: {{ .Values.namespace }}
    {{- end }}
  {{- else }}
    namespace: {{ .Values.namespace }}
  {{- end}}
  name: {{.Values.name}}
</code></pre>

<p>You could use a variable and also <code>{{with}}</code> (which sets the dot), e.g.:</p>
<pre><code>{{- $ns := .Values.namespace -}}
{{- with .Values.global }}{{ with.namespace }}{{ $ns = . }}{{end}{{ end -}}
namespace: {{ $ns }}
name: {{.Values.name}}
</code></pre>
