How to extract the Image parameter from a local md file

Hi All,

I am trying to build a shortcode which would display the image by extracting the image parameter from a separate md file.

The code I could come up with is as below. I know this is wrong and it’s not working, but just trying to illustrate what I am trying to achieve.

<img src="{{ readFile "/content/english/folder1/testfile.md" }}.Params.image">

I want to read the image parameter in testfile.md and use it to display the image for the shortcode.

Note that I want to read the parameters of testfile.md and use it to display an image within a separate file eg testfile_new.md

Please help with code. I am relatively new to this.

Thanks.

See https://gohugo.io/functions/getpage/.

markdown:

{{< foo "/english/folder1/testfile" >}}

layouts/shortcodes/foo.html

{{- with .Get 0 -}}
  {{- $otherPage := $.Site.GetPage . -}}
  {{- with $otherPage.Params.image -}}
    <img alt="" src="{{ . }}">
  {{- end -}}
{{- else -}}
  {{- errorf "The '%s' shortcode requires one positional parameter, the path to the other page. See %s" .Name .Position -}}
{{- end -}}
3 Likes

Thank You so much. It works perfectly :slight_smile:

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