Adding multiple content variables in one layout file?

Hi all,

I’m new to Jekyll and trying to figure out how to modify the site I’ve been given, specifically the layout files.

The layout file is using Dynamic tabs in the form of nav-pills. The site originally had two tabs, the first with some in-file html code and the second contains the {{ content }} variable. I’ve added a 3rd tab and my question is how do I add another {{ content }} variable that will reflect a page2.md file that I have while maintaining the original {{ content }} link to page1.md?

My code is similar to the below:

<div class="tab-content" id="pills-tabContent">

  <div class="tab-pane fade show active" id="pills-view" role="tabpanel" aria-labelledby="pills-view-tab">
    <div>
       [Some unrelated in-file HTML]
    </div>
  </div>

  <div class="tab-pane fade" id="pills-compare" role="tabpanel" aria-labelledby="pills-compare-tab">
    <div>
      {{content}}
    </div>
  </div>

  <div class="tab-pane fade" id="pills-glossary" role="tabpanel" aria-labelledby="pills-glossary-tab">
    <div>
      {{content}}
    </div>
  </div>
</div>

How do I get the {{content}} variable associated with pills-glossary tab to display a specific .md file I have?

You could do something like

_includes/template.html

<div>
    {{ first-section }}
</div>
<div>
    {{ second-section }}
</div>

page.md

{% capture first-section %}

Here is my first section content!

{% endcapture %}

{% capture second-section %}

Here is the second section!

{% endcapture %}

{% include template.html %}

Thanks! How would I call those sections in my template file… Just use {{ first-section}} or would I need to use an include call to pull the .html file?

Ah yes sorry I forgot a part, you need to add

{% include template.html %}

at the end of page.md

Got it!

When I’m referencing the sections that I created in my layout file, I’m using {{ section 1}} and {{ section 2 }} but that doesn’t seem to be working. Is this another way to call these sections in the layout file, similar to how the {{ content }} variable would work?

It doesn’t seem to work in layouts, from what I read on StackOverflow, so you have to use include

Makes sense. Any idea what the right syntax for that would be? I’m trying the following, but it’s not compiling. I’m sure I just need to set something to section-one instead of just passing it in, but I’m not sure what.

{% include template.html section-one %}

You shouldn’t need to pass it at all, just including it. I just remembered I did a gist explaining that for another post so here it is, if it can help you : _includes index.html · GitHub

Did you use those sections you created in a layout file anywhere? Just not sure how to use the include there.

What I told you was just a hacky solution anyway, I just found this plugin which seems very good : GitHub - rustygeldmacher/jekyll-contentblocks: A Jekyll plugin giving you something like Rails' content_for

the only way to include page2.md is if it is an include. But then it would not be its own page and other than being able to include it on another page I don’t see an advantage.

Why can’t you just use html like the first one does?

another option is a data file, I use it for things that repeat a pattern like faqs.