Instantly share code, notes, and snippets.

Embed
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:

<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

This comment has been minimized.

Show comment
Hide comment
@knurdtech

knurdtech May 15, 2013

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

knurdtech commented May 15, 2013

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

@jesusangelm

This comment has been minimized.

Show comment
Hide comment
@jesusangelm

jesusangelm May 15, 2013

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

jesusangelm commented May 15, 2013

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

@tfausak

This comment has been minimized.

Show comment
Hide comment
@tfausak

tfausak 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.

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

This comment has been minimized.

Show comment
Hide comment
@ultimatedelman

ultimatedelman Apr 11, 2015

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

ultimatedelman commented Apr 11, 2015

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

@bryancolosky

This comment has been minimized.

Show comment
Hide comment
@bryancolosky

bryancolosky Jun 26, 2015

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.

bryancolosky commented Jun 26, 2015

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

This comment has been minimized.

Show comment
Hide comment
@vkatariya8

vkatariya8 Jul 8, 2015

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 commented Jul 8, 2015

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

This comment has been minimized.

Show comment
Hide comment
@herodrigues

herodrigues Sep 23, 2015

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

herodrigues commented Sep 23, 2015

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

@tphbtd

This comment has been minimized.

Show comment
Hide comment
@tphbtd

tphbtd 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-->.

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

This comment has been minimized.

Show comment
Hide comment
@eonist

eonist 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.

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

This comment has been minimized.

Show comment
Hide comment
@rudzainy

rudzainy Mar 7, 2016

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

rudzainy commented Mar 7, 2016

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

@fabiocosta0305

This comment has been minimized.

Show comment
Hide comment
@fabiocosta0305

fabiocosta0305 Jun 23, 2016

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

fabiocosta0305 commented Jun 23, 2016

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

@ahmadajmi

This comment has been minimized.

Show comment
Hide comment
@ahmadajmi

ahmadajmi Dec 8, 2016

I use the following

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

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

ahmadajmi commented Dec 8, 2016

I use the following

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

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

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost 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 }}

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