A Better Way to Inject Content into a Jekyll Post

Monday, March 28, 2016

In a previous post, I described a method to inject content into a Jekyll post. The method worked but felt hacky and inelegant. Additionally, you could only inject content one time in a Jekyll post.

Sverrir Sigmundarson commented on that post with a new method that is infinitely better and a lot more elegant than what I previous created.

His method creates a new Jekyll Tag that can be injected many times anywhere in a Jekyll post.

You can find Sverrirā€™s original method in a Gist on his GitHub. Replace CONTENT TO INJECT with whatever content you want to inject. Then insert the following code everywhere in your Jekyll post you want the injected content to be displayed:

{% ads %}

Since publishing the Gist, Sverrir has written a blog post with an updated and more extensible Jekyll Tag. The updated method allows you to inject different content in different places within a Jekyll post.

References

Create a custom Liquid tag as a Jekyll plugin



comments powered by Disqus