How can another file be Included in a Hugo/Markdown page?

GreenMatt picture GreenMatt · Sep 16, 2016 · Viewed 8.6k times · Source

Recently the re-development of a web site was given to me. The re-worked site is to be done in Markdown and run through the Hugo static site generator.

Is there a way to include other files in a Markdown web page processed through Hugo? If so, how? Unless I've missed something, this isn't addressed in the Hugo docs.

With HTML and some servers (Apache, at least) you can do something like:

<html>
<body>
Some content
<!--#include virtual="name_of_first_file_to_include" -->
More content
<!--#include virtual="name_of_second_file_to_include" -->
Still more content
</body>
<html>

I've tried creating a template page which puts stuff like "Some content" and "More content" into the template and then the included stuff in my .md file which gets "included" via {{ .Content }} in the template. However, 1) That seems like the wrong way to use a template. 2) I've not figured out a way to bring in more files if I need them.

Answer

bep picture bep · Sep 30, 2016

For content files there are two options:

  1. Shortcodes. Powerful and documented.
  2. Use mmark as the markdown rendering engine with its include feature. Rename the content files to "*.mmark". See https://github.com/miekg/mmark

I am the maintainer of Hugo.