readFile does not parse shortcodes

how can I achieve the following stuff? I have this shortcode to include .md files into other .md files, this is super useful for tabbed content, to have content for each tab into different files:
includeMarkdown.html

{{ $includePath := (print .Page.Dir (.Get 0)) | printf "./content/%s" }}
{{ readFile $includePath | markdownify }}
{{ .Inner }}

also I have number of shortcodes for simplified rendering for blocks like quotes, tips blocks, hero section and etc, like wrapping components.

Whenever I include files into base .md file like this

{{% includeMarkdown "path" /%}}

any shortcodes inside child-file does not work, coz markdownify render all shortcodes as plain text without any parsing. What am I doing wrong? Is there anyway to parse those files with “Blackfriday” or what HUGO is using for self rendering?

Hey, stop moving this back into #tips-tricks. You have a #support question, that is where it goes. Tips and Tricks are when someone is sharing something, not asking a question.

1 Like

@vit.pankin try replacing your shortcode body with

{{ $file := .Get "file" }}
{{- $file  | readFile | markdownify -}}

It works for me :slight_smile:

@Weru I have the same issue as @vit.pankin.
Here is my shortcode:

{{$file := printf "embeds/%s" (.Get 0)}}
{{- $file  | readFile | markdownify -}}

All content within the file being output are rendered correctly except the shortcode. It renders out as plain text.
Do you have any suggestions?

1 Like

I was trying to do this as well but ran into the same issue as everyone else. I don’t think its currently possible but maybe @bep knows of a solution or workaround.

1 Like

@Weru
Does this still work for you in 0.55.6?

@Harun, @vit.pankin

@Weru
Does this still work for you in 0.55.6?

No it doesn’t, the child-file shortcodes are not processed. In fact, I observed that the readFile function reads the child files as plain text.

I tried an alternative approach using the GetPage function:

<!-- file shortcode -->
{{ $file := .Get 0 }}
{{ $page := .Site.GetPage $file }}
{{ with $page }}
  {{ .Content }}
{{ end }}
<!-- call the shortcode from content files -->
{{< file "about.md" >}}

It works well; all the shortcodes are all processed :slight_smile: .

5 Likes

Thanks Weru! That works.

1 Like

Thanks @Weru for posting a working example!

1 Like

@Weru , tried with your solution, but it brought some other problems.

Like titles in child md file are not processed as right side menu.

@Jiang_Patrick,

I would need to see your code to see what’s wrong

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