I'm using the following code in my template to truncate the body of an entry (coming from a Rich Text field):

{{ entry.body | slice(0, 500) | markdown }}

To this, I'd like to add ... as a string, so that it will output like:

Words words words...

Since the field part I'm using outputs into its own <p> tag, adding the ... into the HTML itself has them sitting in two different tags. I've tried using |join but I must be doing something wrong, its putting the first part into a separate <p> tag than the ...

Thanks for your help!


Try something like

{{ (entry.body | slice(0, 500) ~ '...') | markdown }}
  • This is probably really close, but it's not converting it to markdown. Is there a smarter way of outputting the Rich Text's content?
    – jasonetco
    Mar 19 '16 at 19:40
  • 1
    This works perfectly: {{ (entry.body | slice(0, 500) ~ '...') | markdown }}
    – jasonetco
    Mar 19 '16 at 19:51

You might find the Hacksaw plugin useful for this https://github.com/ehousestudio/craft_hacksaw/ this will truncate text for you and has a wealth of options available for doing so, specifically the append parameter, which will do exactly what you want :)

  • Cool, thanks! I'd rather not use a plugin, but this will be my back up answer :)
    – jasonetco
    Mar 19 '16 at 19:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.