Someone asked earlier today about excerpts, and how to keep the tags. Since the built in excerpt()
strips everything, @texnixe suggested a custom field method.
It just so happened the project I am working on at the moment needs this, so I Googled around, one thing led to another and Kirby Chopper was born.
I really cant take much credit for this, it’s based on the work described in an excellent article by Patrick Galbraith. I simply wrapped it up into a plugin and tweaked it a little.
It’s a beta plugin, so please, go careful. Feel free to post issues or PR’s over on Github.
Usage
To trim to 200 characters and append ellipsis on the end:
<?= $page->text()->chopper(200, 'chars', '…') ?>
To trim to 50 words and append ellipsis on the end:
<?= $page->text()->chopper(50, 'words', '…') ?>
Defaults to words and an ellipsis, so if you just want 20 words and an ellipsis on the end, its shorter to write:
<?= $page->text()->chopper(20) ?>
To change the default list of kept tags, add this line to your config.php
and amend accordingly:
c::set('chopper.keep', '<p><a><strong><em><sub><sup><blockquote><figure><img>');