SOLVED: How to 'include' other files

I’ve searched high and low, and this article seems close, but I’m not there yet.

I have a lump of markdown that I want to include in two ‘content’ files, because I don’t want to repeat myself.

Based on the linked comment, above, I have shared markdown in /layouts/partials/shared-markdown.html, and I a shortcode that looks like this:

{{ partial "shared-markdown.html" | print | markdownify }}

But Hugo doesn’t like my having placed markdown in a .html file, so I haven’t even got to step one :frowning:

ERROR: 2016/12/16 15:40:36 template.go:477: template: partials/shared-markdown.html:3: unexpected “<” in command

Can anybody point me in the right direction? I want to share the same markdown content in multiple places.

Thanks (again!)

Consider Mmark.

Thank you. “Consider Mmark” seems like good advice, and I have investigated. The ability to include arbitrary files is exactly what I want. There are hints that others have done this successfully, but no matter what I try the file I am attempting to include cannot be found.

Mmark docs tell me

Including other files can done be with {{filename}}, if the path of filename is not
absolute, the filename is taken relative to working directory of the Mmark process.

Given “content/quick-start/index.mmark”, what variation of {{ ugh.mmark }}, and it’s location on disk will cause it to be actually included – ideally using a relative path?

I believe I have tried every combination of everything, including an absolute path of /tmp against a chmod a+rw’ed file and I get nothing but no such file or directory

What incredibly simple thing am I missing? Thank you!

2017/01/09 10:48:58 mmark: failed: ` ugh.mmark ': open  ugh.mmark : no such file or directory
2017/01/09 10:48:58 mmark: failed: ` content/ugh.mmark ': open  content/ugh.mmark : no such file or directory
2017/01/09 10:48:58 mmark: failed: ` /content/ugh.mmark ': open  /content/ugh.mmark : no such file or directory
2017/01/09 10:48:58 mmark: failed: ` partials/ugh.mmark ': open  partials/ugh.mmark : no such file or directory
2017/01/09 10:48:58 mmark: failed: ` /partials/ugh.mmark ': open  /partials/ugh.mmark : no such file or directory
2017/01/09 10:48:58 mmark: failed: ` layouts/partials/ugh.mmark ': open  layouts/partials/ugh.mmark : no such file or directory
2017/01/09 10:48:58 mmark: failed: ` /layouts/partials/ugh.mmark ': open  /layouts/partials/ugh.mmark : no such file or directory
2017/01/09 10:48:58 mmark: failed: ` /home/kerry/hugo/sample/layouts/partials/ugh.mmark ': open  /home/kerry/hugo/sample/layouts/partials/ugh.mmark : no such file or directory
2017/01/09 10:48:58 mmark: failed: ` /tmp/ugh.mmark ': open  /tmp/ugh.mmark : no such file or directory
2017/01/09 10:48:58 mmark: failed: ` ugh.mmark ': open  ugh.mmark : no such file or directory
2017/01/09 10:48:58 mmark: failed: ` content/ugh.mmark ': open  content/ugh.mmark : no such file or directory
2017/01/09 10:48:58 mmark: failed: ` /content/ugh.mmark ': open  /content/ugh.mmark : no such file or directory
2017/01/09 10:48:58 mmark: failed: ` partials/ugh.mmark ': open  partials/ugh.mmark : no such file or directory
2017/01/09 10:48:58 mmark: failed: ` /partials/ugh.mmark ': open  /partials/ugh.mmark : no such file or directory
2017/01/09 10:48:58 mmark: failed: ` layouts/partials/ugh.mmark ': open  layouts/partials/ugh.mmark : no such file or directory
2017/01/09 10:48:58 mmark: failed: ` /layouts/partials/ugh.mmark ': open  /layouts/partials/ugh.mmark : no such file or directory
2017/01/09 10:48:58 mmark: failed: ` /home/kerry/hugo/sample/layouts/partials/ugh.mmark ': open  /home/kerry/hugo/sample/layouts/partials/ugh.mmark : no such file or directory
2017/01/09 10:48:58 mmark: failed: ` /tmp/ugh.mmark ': open  /tmp/ugh.mmark : no such file or directory

If you want to play along at home, here’s a small script that illustrates the problem:

 rm -rf include-fail

 hugo new site include-fail
 cd include-fail
 hugo new _index.mmark
 echo 'Before Include >>> ' >> content/_index.mmark
 echo '{{ /tmp/include-this.mmark }}' >> content/_index.mmark
 echo '<<< After Include' >> content/_index.mmark

 # Here is the file I want to include
 echo ' -- this should be included --' > /tmp/include-this.mmark

 git clone --depth=1 https://github.com/key-amb/hugo-theme-bootie-docs.git themes/bootie-docs

 hugo server --theme=bootie-docs --buildDrafts

When it runs we see:

Checking connectivity... done.
Started building sites ...
2017/01/09 11:38:04 mmark: failed: ` /tmp/include-this.mmark ': open  /tmp/include-this.mmark : no such file or directory
Built site for language en:

Any ideas?

You should ask on the Mmark support forum, but my first try would be to try a relative include of sorts.

For the record, I’ve raised this bug in mmark

For future viewers, the problem was the whitespace.

This fails:

{{ include-this.mmark }}

…but this succeeds:

{{include-this.mmark}}
1 Like

This is an old thread, but in case someone stumbles up on it: mmark will be deprecated, so it would be better not to depend on it. There’s a nice thread here that shows how to build an include shortcode:

3 Likes