A small plugin for Kirby 2 that creates excerpts from fields but keeps the html tags intact.
Kirby Chopper Plugin
Sometimes it can be useful to be able to trim a long article down so it can be displayed in something like a blog list. In an ideal world, you would write this text by hand but it can be useful to have a fallback solution if you are pushed for time.
Unlike Kirby's built in Excerpt field method which only returns plain text, this plugin creates excerpts from fields via kirbytext but keeps HTML tags. This means all tags, including images. You can set a character or word limit.
To use this plugin, place all the files in site/plugins/chopper.
Defaults to words and an ellipsis, so if you just want 20 words and an ellipsis on the end:
<?= $page->text()->chopper(20) ?>
To trim to 200 characters and append ellipsis on the end:
<?= $page->text()->chopper(200, 'chars') ?>
To trim to 50 words and append an arrow on the on the end:
<?= $page->text()->chopper(500, 'words', '→') ?>
To change the default list of kept tags, add this line to your config.php and amend accordingly: