SiddharthaRT
SiddharthaRT

Reputation: 2297

How to include a HTML file inside a markdown file in jekyll?

I have a jekyll site with filestructure like so:

▾ _includes/
    post-entry.html
▾ _posts/
    2012-11-25-first-post.markdown
index.markdown

In my index.markdown, I want to include a post-entry.html like this:

{% for post in site.posts %}
* {% include post-entry.html %}
{% endfor %}

But this appears as a HTML code snippet in the blog. How can i prevent the HTML from being protected?

Upvotes: 9

Views: 15640

Answers (4)

David Silva Smith
David Silva Smith

Reputation: 11706

The problem is the parser views the HTML as code blocks. The best way would be to turn off code blocks like I asked in this question

To work around use the replace tag:

{% capture includeGuts %}
{% include post-entry.html %} 
{% endcapture %}
{{ includeGuts | replace: '    ', ''}}

Upvotes: 5

Zaz
Zaz

Reputation: 48709

Use {{ post.content }} instead.

Here's the code I use on my website as an example:

{% for post in site.posts %}
    <a href="{{ post.url }}">
        <h2>{{ post.title }} &mdash; {{ post.date | date_to_string }}</h2>
    </a>
    {{ post.content }}
{% endfor %}

Upvotes: 0

cboettig
cboettig

Reputation: 12677

You can use liquid tags in any markdown file so long as it has YAML header matter. For instance, check out the index.md given in the jekyllbootstrap template for Jekyll sites.

If you link to your actual index.markdown or your repository itself (e.g. if it's on github), we could probably get a better idea of what has gone wrong. Your example should work, though you might need to use HTML list element <li> rather than the markdown *.

Upvotes: 12

Joshua Hornby
Joshua Hornby

Reputation: 383

You can't. Markdown files are just text files with styling. If you want to use the Liquid tags you will have to do so in your _layouts

If I am guessing right you want this markdown file on your index page? So in the default.html layout after the {{ content }} tags you could then use the liquid tags you want to use. There is no need to mix the markdown files with code.

Upvotes: -8

Related Questions