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

14,201

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: '    ', ''}}
Share:
14,201
SiddharthaRT
Author by

SiddharthaRT

In love with Python. Still advancing in small steps.

Updated on June 04, 2022

Comments

  • SiddharthaRT
    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
    SiddharthaRT over 11 years
    I was relaxing on my beanbag and staring at the ceiling when it hit me. Thanks.
  • cboettig
    cboettig over 11 years
    I'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
    SiddharthaRT over 11 years
    In 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
    cboettig over 11 years
    Cool, so it sounds like everything is working with the liquid code in the index.markdown file as you intended now, yes?
  • SiddharthaRT
    SiddharthaRT over 11 years
    No. 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
    RobW almost 11 years
    This should be the answer. Using plenty of liquid, including include tags, on the Jekyll project I'm working on right now.