Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jekyll - How to split content defined in .md file into separate elements

Tags:

jekyll

I've just installed Jekyll and I'm following a few tuts. I get that you define your content in a .md file in the root and that generates your html file based on the layout file you chose but what I don't get is how to split your {{ content }} up.

Say for instance I want one piece of content from my .md file in a <article> and the other in an <aside> How would I go about doing this? Code in question is pasted below. Thanks

.md file

---
layout: page
title: Page Test
permalink: /page-test/
bodyclass: page-test
---

Article content
* Hey this is my content!

Aside content
* Test links

Layout file

---
layout: default
---
<div class="post">

<header class="post-header">
<h1 class="post-title">{{ page.title }}</h1>
</header>

<article class="post-content">
{{ content }}
</article>

<aside>

</aside>

</div>
like image 519
Clinton Green Avatar asked Dec 19 '22 10:12

Clinton Green


1 Answers

You can use the post.excerpt functionality.

_config.yml

excerpt_separator: "<!--more-->"

post

---
frontmatter
---
Excerpt text
<!--more-->
Body text
....

layout

---
layout: default
---
<div class="post">

<header class="post-header">
<h1 class="post-title">{{ page.title }}</h1>
</header>

<article class="post-content">
{% assign contentArray = page.content | markdownify | split: site.excerpt_separator %}
{{ contentArray.last }}
</article>

<aside>
{{ contentArray.first }}
</aside>

</div>
like image 148
David Jacquel Avatar answered May 26 '23 21:05

David Jacquel