Isset in partial

I have a partial that I include like this:

{{ range .Params.engagements }}
                    {{ partial "partials/about-engagemet.html" (dict "logo" .logo "title"  .title "description" .text  "link" .link)}}
{{ end }}

In the partial I now want to check if the .link is available (set in front matter or not). I tried:

{{ if (isset .Params .link) }}
    <a href="{{ .Params.link }}" target="_blank"><img class="w-full" src="{{ .logo }}" /></a>
{{else}}
    <img class="w-full" src="{{ .logo }}" />
{{end}}

sadly that is not working and I found no answer in the forum. How can that be solved?

{{ if isset . "link" }}

Replace the conditional directive with above should work, since the context (AKA the dot .) is dict "logo" .logo "title" .title "description" .text "link" .link.

I tried that but now I have the link with an empty href

I found a solution in another thread. Working code:

{{ if .link }}
    <a href="{{ .link }}" target="_blank"><img class="w-full" src="{{ .logo }}" /></a>
{{else}}
    <img class="w-full" src="{{ .logo }}" />
{{end}}

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.