Rendering content with shortcode


I have got some yaml data files which contains some page content e.g.

 content: '# foo {{< myshortcode  >}}'

I try to run

.Site.Data.mydatafile.content | markdownify

but the shortcode is not processed. How can I process content of a variable with shortcodes?

You’re supposed to call your shortcodes from your content files. It seems as though you’re trying to call the shortcode from your layouts template. The docs say that shortcodes should only be called from content files.

Yes, shortcodes are currently not processed when you run markdownify.

My problem is, that I have multiple content files which contains equal sections and I would like to store these sections once and would like to include it into the content file. So I would like to store the content once and include it multiple time like the C include command.

Did you have any suggestion to do this?

You could handle it in your templates. Say you had a front matter param includeContent. If that’s true, then include the content. There are many other ways to do this too.

I use includes a lot in my writing and while learning Hugo, I’ve done a lot of experiments trying to figure out the best way to do this. My solution is to write my content in AsciiDoc format because it supports includes (and a lot of other good stuff). My path towards this solution included trying:

  • shortcodes (as you’ve tried)
  • mmark format, which supports includes
  • org-mode format, which supports includes
  • pandoc, which supports includes

You can read about the content formats that Hugo supports here: