This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

willstocks_tech
willstocks_tech

Hi guys,

I'm hoping someone out there can help me - basically, I'm looking to setup an "excerpt" for blog posts which is truncated down to about 50 characters. I'm new to October, so still on a bit of a learning curve!

At the moment I have: <div class="excerpt">{{ str_limit(post.summary|raw , 50) }}</div>

This works OK, except for when there's an image within that first 50 characters (let's say, the 48th character) which breaks everything. Essentially, what

I'm looking to do in this case is: 1) Rather than limit to 50 characters, can I limit to say, 20 words? 2) Ignore images as part of this excerpt - skip around them entirely and use the words either side of them?

Last updated

willstocks_tech
willstocks_tech

I think I might have worked this out...

<div class="excerpt">
    {{ str_limit(post.summary|striptags|raw, 50) }}
</div>

Including the striptags bit seems to do the trick for removing the image and only handling the word content. 50 still limits characters, not words but I can probably work around that!

1-2 of 2

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.