Cross-reference in data files with markdownify

I’m using data files for dynamic content that is displayed in the website. Such as:

packages:
    title: "Package A"
    content: "This is markdown for **A**"

And, in the layout file, I have something like:

{{ with $data.products.packages }}
<div>{{ .content | markdownify}}</div>
{{ end }}

In the content, I’d like to use the cross-referencing functionality, for rendering a link to a post. Something like:

content: "This is a link to [an article]({{< ref \"document.md\" >}})"

However, this does not seem to work.

So, my question is how can I use cross referencing in data content that I’m passing through markdownify?

a repository could help us

I would try this - not tested!
content: "This is a link to [an article]({{% ref \"document.md\" %}})"

Hello. Unfortunately, it doesn’t work. I’ve tried using other shortcodes (default, such as gist or figure) and they are never processed. It seems that markdownify does not handle shortcodes?!

Shortcodes are a Hugo concept, not a markdown concept, so markdownify would probably only treat the code as string.

You probably need a combination of resources.FromString and resources.ExecuteAsTemplate.

Given data/test.json:

{
    "foo": "{{ add 1 2 }}",
    "bar": "{{ ref . `square.md` }}"
}

you can try:

{{ $data := site.Data.test }}
{{ $data }}: map[bar:{{ ref . `square.md` }} foo:{{ add 1 2 }}]

Turn the data into a resource, then ExecuteAsTemplate:
{{ $test := jsonify $data | resources.FromString "test.json" | resources.ExecuteAsTemplate "test.json" . }}

$test.Content is a string, use transform.Unmarshal to turn back into a map
{{ $result := $test.Content | transform.Unmarshal }}
So now you have:

{{ $result }}     : map[bar:http://localhost:1313/square/ foo:3]
{{ $result.foo }} : 3 
{{ $result.bar }} : http://localhost:1313/square/