2

I have a Jekyll site with a main column and a sidebar. The main template looks a bit like this:

<div class="main-column">
    {{ content }}
</div>
<div class="sidebar">
    <!-- this is the issue -->
</div>

Now, getting post content into the main column is easy. But what can I do to move some part of a post into the sidebar? An example of a post:

# This is a Markdown post

Some regular content.

This should be in sidebar.

I have tried the capture command to save a part of the post into a variable and insert it into the sidebar div later. That doesn’t work, since the variables set in the page don’t make it back to the template (related Stack Overflow question).

I considered putting the sidebar contents into the YAML front matter, but that’s an ugly hack. (The content can be quite long, if not anything else.)

Also, I want to keep the sidebar content in the same file as the main post.

What are my options?

Community
  • 1
  • 1
zoul
  • 102,279
  • 44
  • 260
  • 354

1 Answers1

0

The best option is to put your sidebar markup into your post content, not the main template. If it is content related to that specific post then that is also the logical place for it to live; with the rest of the post content.

Alternatively you could simply manipulate a section of content by adding a class to a paragraph of your markdown, e.g.

My lorum ipsum sidebar content.
{: class="sidebar" }
Seth Warburton
  • 2,234
  • 1
  • 16
  • 17
  • Inserting the sidebar markup in the post content is kind of problematic. I’d like to stick with Markdown, but once I insert a ` – zoul Feb 05 '15 at 07:24
  • Those are your options, if you want post specific sidebar content. Put it in front-matter or put markup in your post. – Seth Warburton Feb 05 '15 at 08:47