Ways to include a content file in another in version 0.32+

I know that mmark supports including one content file in another, as discussed in github.com/miekg/mmark/wiki/Syntax#including-files.

I’ve been reading the documentation about bundles and pandoc and trying to figure out if there are alternative ways to do this in Hugo version 0.32 (and above). A scenario where I’d like to do this is I’m writing about a tech topic in a markdown file and I want to include a long excerpt of code. I know I could paste the code within code fences, but it would be much nicer to have the code in a separate file so I can edit just that code file in the future.

Thanks for any tips!

You could create a snippets section, and create a shortcode to include the content of a given snippet. That’s one way.

Your question is very general, the answer to that is long (see documentation), but your use case may be inspired by this commit:

Note that

  1. Shortcodes can be nested
  2. There is a readFile template func
  3. There is a highlight template func
  4. Template funcs can be piped