Here is how you can use shortcode’s to include a another markdown file in hugo. Including markdown will help you reuse contents from another blog markdown post/article

With this shortcode our clients were able to save hour, and avoid duplicate contents.

file: <them_dir>/layout/shortcode/includePage.html

{{- $page := .Get "page" -}}
{{- $title := .Get "title" -}}
{{- $more := .Get "more" -}}
{{- with .Site.GetPage $page -}}
    {{- if $title -}}<h3>{{- $title -}}</h3>{{- end -}}   
    {{- .Content -}}
    {{- if eq $more "true" -}} <a href="{{.RelPermalink}}">Read more</a>{{- end -}}
{{- else -}}
    {{- warnf  "[shortcode/includePage] Page not found %q" $page -}}
{{- end -}}

Here is how you use this shortcode to include content, title and more are optional

{{< includePage page="blog/page_to_include.md" title="Output" more="true" >}}

Below what you see is the content included from another markdown post.

Output

devnodes.in was started on 13th Jan, 2023.

Youtube channel: https://www.youtube.com/@devnodes

Made with Hugo & Bootstrap

Read more