Skip to content
Discussion options

You must be logged in to vote

After a lot (and I mean a lot) of trial and error, I was able to come up with what it seems to be a more elegant solution

{{- with .cxt}} {{/* Apply proper context from dict */}}
{{- if (and .Params.featuredImage (not $.isHidden)) }}
<figure class="entry-cover">
    {{- $cover := (.Resources.ByType "image").GetMatch (printf "*%s*" (.Params.featuredImage)) }}
    {{- if $cover -}}{{/* i.e it is present in page bundle */}}
        <img loading="lazy" src="{{ (path.Join .RelPermalink .Params.featuredImage) | absURL }}">
    {{- else }}{{/* For absolute urls and external links, no img processing here */}}
            <img loading="lazy" src="{{ (.Params.featuredImage) | absURL }}">
    {{- end

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@brunomiguel
Comment options

Comment options

You must be logged in to vote
1 reply
@brunomiguel
Comment options

Answer selected by brunomiguel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants