Create a gist now

Instantly share code, notes, and snippets.

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:

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

Which would produce:

@knurdtech

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

@jesusangelm

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

@tfausak
tfausak commented May 20, 2013

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

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

See the documentation for more information.

@ultimatedelman

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

@bryancolosky

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.

@vkatariya8

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?

@herodrigues

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

@tphbtd
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
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
rudzainy commented Mar 7, 2016

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

@fabiocosta0305

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

@ahmadajmi

I use the following

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

http://stackoverflow.com/a/20483107/558777

@taylex
taylex 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