Custom Shortcode (Include, Tag) in Jekyll with Parameters and Multiline Text

Viewed 12

I'd like to create something like a shortcode in Jekyll for a blockquote which also states the source of the quote in a nicely formatted way.

The shortcode could look something like this:

{% quote author="My Author" %}
This is the quote content
spanning multiple lines

And paragraphs
{% endquote %}

What's the best way to achieve this in Jekyll?

My Research

I have found two systems in Jekyll that can be used similar to shortcodes:

However, both of these systems seem to have limitations.

HTML Includes

An include in use looks like this:

{% include note.html content=download_note %}

It is possible to use content from captures for parameters, so we could create the following include file:

<blockquote>
    {{ include.quote | markdownify }}
    <p><em>{{ include.author }}</em></p>
</blockquote>

And use it in a blog post like this:

{% capture quote %}
This is the quote content
spanning multiple lines

And paragraphs
{% endcapture %}
{% include quote.html quote=quote author="My Author" %}

It works, but in my opinion it's not really a nice approach to use when writing blog posts.

Custom Tags

Tags sound very promising, but the documentation only shows two ways to use them:

{% render_time page rendered at: %}

and

{% render_time %}
page rendered at:
{% endrender_time %}

Both methods only provide a single attribute to the Ruby code, the content. And I have found a blog post that provides multiple attributes using string concatenation or JSON. To me this sounds like there's really no way to provide multiple arguments to a jekyll tag plugin. Can this really be the case?

0 Answers
Related