Embedding partials in markdown using a shortcode

Sometimes you wish to add a partial content within a Markdown file, unfortunately this is not possible by default. But wish your tears away - here we show you a workaround to make partials accessible within your markdown.

For whatever reason your project needs to support a solution like this. Here we come with the workaround:

Architecture

The architecture is pretty easy. First, we will create a shortcode called partial and since there is a way to access the real partial within the shortcode we will open the partial within the shortcode.

Code

Let’s create the following file:

shortcodes/partial.html

{{ partial (.Get 0) }}

Done.


Usage Example

content/sample-content.md

+++
title = "Some basic Sample content"
+++

# Embedding a partial.
In this article we will embedd conten from a partial.
{{< partial "partial-name" >}}

Lorem ipsum dolor.