Skip to content

Instantly share code, notes, and snippets.

@samhernandez
Created January 3, 2019 13:03
Show Gist options
  • Save samhernandez/8608b1887471484777155e4435f971d4 to your computer and use it in GitHub Desktop.
Save samhernandez/8608b1887471484777155e4435f971d4 to your computer and use it in GitHub Desktop.
Twig text truncation
{# limit to 300 characters, then 40 words, and remove last word which is likely cut off #}
{{ content | slice(0, 300) | split(' ') | slice(0, 40) | slice(0, -1) | join(' ') | raw }}…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment