Skip to content

Instantly share code, notes, and snippets.

@james2doyle
Created September 19, 2013 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save james2doyle/6629712 to your computer and use it in GitHub Desktop.
Save james2doyle/6629712 to your computer and use it in GitHub Desktop.
Twig PHP filter to grab the first paragraph of the piped variable
<?php
$filter = new Twig_SimpleFilter('first_paragraph', function ($string){
$string = substr($string, 0, strpos($string, "</p>") + 4);
return $string;
});
// {{ content|first_paragraph }}
@ureimers
Copy link

Nice one. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment