How to render something only if a variable is not empty

hi,
i am filtering my posts by some tag and putting it in a variable. now what is the correct way to render something only if that variable is not empty.
here is my code.
Thanks.

{{ $truncate := default true .Site.Params.truncate }}
{{ $postlist := .Site.Taxonomies.tags.ssc_jobs}}

{{if (eq $postlist "") }}

   {{.Render "nothing"}}

   {{else}}

      {{range first 10 $postlist}}

        {{ if $truncate }}
      
           {{ .Render "summary" }}
        
        {{ else }}
      
           {{ .Render "content" }}
        
         {{ end }}


      {{ end }}

{{end}}

and here is output

You can use with / else:

{{ with $postlist }}
  {{ range first 10 . }}
    ...
  {{ end }}
{{ else }}
 nothing
{{ end }}

(note that the dot context changes inside with, as mentioned also in the docs I linked to)

3 Likes

Thanks,a lot, it solved my problem.