How to include a HTML file inside a markdown file in jekyll?
Solution 1
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 *
.
Solution 2
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: ' ', ''}}
SiddharthaRT
In love with Python. Still advancing in small steps.
Updated on June 04, 2022Comments
-
SiddharthaRT almost 2 years
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?
-
SiddharthaRT over 11 yearsI was relaxing on my beanbag and staring at the ceiling when it hit me. Thanks.
-
cboettig over 11 yearsI'm sorry, but this answer is simply wrong. You can indeed use liquid in an index.markdown file, as I indicate in my answer.
-
SiddharthaRT over 11 yearsIn the file, I had to actually put the code as i mention in top, but I ended up doing as it is now. PS: Dont see the history, it's actually the history of a different repository. Have to do a
rebase
or something. -
cboettig over 11 yearsCool, so it sounds like everything is working with the liquid code in the
index.markdown
file as you intended now, yes? -
SiddharthaRT over 11 yearsNo. Now i'm doing the method that's actually mentioned in the bottom of your link: [like this](git://gist.github.com/4174354.git). When I include it as
{% include post.html %}
, I get an output like so. -
RobW almost 11 yearsThis should be the answer. Using plenty of liquid, including
include
tags, on the Jekyll project I'm working on right now.