简体   繁体   中英

{{ content }} Liquid tag not showing blog posts

Link to repo: https://github.com/AlvSovereign/AlvSovereign.github.io

I am coding my portfolio site, with a link to my blog. The fully processed portfolio site sits in _site/index.html which contains a link to the blog (fully processed link exists in _site/blog.html)

Blog.html at the root of the repo has in the front matter a layout of "bl", which is defined in my layouts folder under " bl.html ".

" bl.html " is the layout I want for my blog page, which contains my includes etc. It also contains the {{ content }} liquid tag.

If I am thinking about this the right way, my posts are being parsed (I think this is the right terminology) into " post.html " - which has the front matter "layout: bl", which then parsed into "bl.html", and that this is so as they both have {{ content }} in each files.

Now all my posts are showing correctly (i think) within _site/(year)/(month) etc. However, they are not ending being parsed through my "blog.html" file, and then visible on my webpage. How I know this is that the fully processed " blog.html " file does not have any of the posts in them.

What will I need to do to solve this issue?

If it helps, I use Prepros for LiveReload, and using LANYON template, http://lanyon.getpoole.com/

{{ content }} refers to all the content that in the file that is being converted to HTML code.

For example, if you are passing a blog post on 'What is Jekyll' to any layout that has the {{ content }} tag, all text other than the YAML front matter will be put in that place. Basically the content of the post. You can also limit the scope by using {{ post.content }} , see Variables for more info here .

So the Liquid {{ content }} variable works as intended.

Looking at your website, I believe you're trying to display all the posts in your blog.html file, so what you're actually asking about is why aren't my posts being displayed (not parsed) in your blog.html file, hence not visible on your webpage.

The reason for that is because you shouldn't use {{ content }} tag for that, what you want instead is something like this snippet of code as mentioned in the Jekyll docs , that will grab all your posts, and display them by post title, as well as a link to that post. Here's the code to display a list of your posts. (taken from the website I linked you)

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

So just swap out {{ content }} in your bl.html layout with that code snippet and you've got what you want.

Additionally, if you also want to display the content/excerpt in the list of posts , just add the liquid tag {{ post.content }} or {{post.excerpt}} like so:

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

Of course, edit the HTML accordingly for your preference. Read the documentation on how to set up post excerpts here , which uses the <!--more--> comment separator for excerpts.

I strongly recommend reading the JekyllRb documentation for more information, it's a lot to read and not always easily understandable, but keep referring to it and you'll understand more in no time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM