1

I want to show latest posts in my bolg.html page. So i used Liquid syntax

But when i used the liquid shown below and run locally, the page shows the code as it is and it doesn't fetch posts from my _posts folder.

The liquid syntax is given below:

liquid syntax

and then the out put is as given below

output

Please help me. Also i'am using a template called Triangle from bootstrap. and i'am hosting on github.

hxri
  • 123
  • 10
  • Do you have liquid installed locally? If you don't, you will need to do that, installing it via command line `gem install liquid` as explained [here](http://liquidmarkup.org/) – Virtua Creative Nov 21 '15 at 04:29
  • still **not** working. – hxri Nov 21 '15 at 07:12
  • Weird... I'll give a better look at your code and compare to mine later and if I find something useful I'll get back to you. – Virtua Creative Nov 21 '15 at 07:40
  • Actually, I was thinking, how are you running `jekyll serve`? Try running it by this command : `bundle exec jekyll serve --safe --watch --baseurl ""` and see if you get an error. This is the safest way to test how GitHub is going to render your Jekyll site. – Virtua Creative Nov 21 '15 at 07:48
  • Post your code as text please. And if you have a repository url it's even better to try to help you. – David Jacquel Nov 21 '15 at 20:07

4 Answers4

4

I think I know what's wrong. Your loop is not working because you said {% for blogpost in site.posts%} and then you call the loop by post and not blogpost. Try changing the for loop to:

{% for post in site.posts %} 

and you should be fine!

If this answer is correct or useful, please mark it! Thanks! ;)

Virtua Creative
  • 1,721
  • 1
  • 10
  • 17
  • That does't matter at all. But i changed "blogpost" to "post" and still i have the problem. – hxri Nov 21 '15 at 08:17
  • 1
    Would you please post you code as text here so I can copy it and paste into a document in order to run some tests? Also, can you include your posts yaml front matter? – Virtua Creative Nov 21 '15 at 16:00
1

This might be a bit late but I just had a similar issue.

I originally had this in my default.html

---
page.title: My Blog
---
<!DOCTYPE html>
<html>
    <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>{{ page.title }} | My Blog - Musings of a Software Developer from Norwich</title>
    <link rel="stylesheet" href="{{'/assets/main.css' | prepend: site.baseurl}}">
</head>   
<body>
    {% include nav.html %}

    <div class="content">
        {{ page.content }}
    </div>
    <script src="{{'/node_modules/jquery/dist/jquery.min.js' | prepend: site.baseurl}}"></script>
    <script src="{{'/node_modules/popper.js/dist/popper.min.js' | prepend: site.baseurl}}"></script>
    <script src="{{'/node_modules/bootstrap/dist/js/bootstrap.min.js' | prepend: site.baseurl}}"></script>
</body>

</html>

and in my blog.html, I had

---
title: Blog
layout: default
---

<h1>Latest Posts</h1>

<ul>
    {% for post in site.posts %}
    <li>
        <a href="{{ post.url }}">{{ post.title }}</a>
    </li>
    {% endfor %}
</ul>

Answer

I noticed that when I removed the layout from the frontmatter, then the loop was running correctly, so I put my layout back in and it stopped working. Then on closer comparison with another site I was doing, I noticed in my layout I had {{ page.content }}. So I updated this to just be {{ content }} and hey presto, I got my theme and it looping over the blog posts like I wanted it too. Hopefully this might help someone in the future

Chris
  • 387
  • 6
  • 20
1

I'm really late to the party but better late than never eh?

By looking at the screenshots you've posted it seems you're using {{ page.content }} in your layout template as liquid tags don't seem to be rendering as you expect them to. Maybe you need to use {{ content }} instead so your content renders correctly before being outputted to the page?

Joel Murphy
  • 2,414
  • 2
  • 26
  • 47
1

I solved this by deleting the index.html in the root directory and creating an index.md. After this, everything worked as expected!

DigitalCodon
  • 145
  • 2
  • 7