Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Example of how to use Jekyll's `excerpt` tag.

If your post looked something like:

# Awesome Blog Post

Here is an example post to show how to use the new `excerpt` tag.

The excerpt tag provides a quick and easy way to tease a post by exposing only the first paragraph such as on a blog index page.

Then in your template, you could create an index file like this:

{% for post in site.posts %}
    <a href="{% post.permalink %}">{% post.title %}</a>
    <p>{{ post.excerpt }}</p>
{% endfor %}

Which would produce:

Trying to figure out Jekyll. Getting this error when generating "Liquid Exception: Unknown tag 'post' in"

same here! Liquid Exception: Unknown tag 'post' error.

tfausak commented May 20, 2013

Use {{ post.excerpt }} instead of {% post.excerpt %}. For example:

  {% for post in site.posts %}
      <a href="{{ post.permalink }}">{{ post.title }}</a>
      <p>{{ post.excerpt }}</p>
  {% endfor %}

See the documentation for more information.

Even with {{ instead of {%, this doesn't work for me. It always returns the full content of the post...

Remember to use in the actual post to tell Jekyll where it should 'cut' the post for the excerpt content. You can also set excerpt_separator globally in your _config.yml to whatever may tickle you fancy.

I have an image to start off my post, and the excerpt shows only the image. How can I show text and not the image?

@vkatariya8 I have the same situation here. My "solution" was put the image at the end of the post.

tphbtd commented Oct 4, 2015

@vkatariya8 I have excerpt_separator: "<!--more-->" in my _config.yml. In the post, I then place an image then the first paragraph (the default excerpt) followed by <!--more-->.

eonist commented Jan 15, 2016

This didn't work for me either, I had to escape the html more comment inside the liquid expand. Then it worked.

rudzainy commented Mar 7, 2016

I believe the excerpt method takes the whole first paragraph if you don't specify the separator.

Someone could say me the best excerpt_delimiter for using --- as excerpt delimiter?

I use the following

{{ post.content | strip_html | truncatewords:75 }}


ghost commented Feb 27, 2017

Thanks @ahmadajmi
If you leave out "strip_html" a post image will show if it is before the truncate.
The following works as well.
{{ post.excerpt | strip_html | truncatewords:75 }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment