Excerpts with working styling/tags?

Any ideas on keeping the styling with excerpts? Im new to this and cant seem to figure it out.
Im using this to get a blurb from one of the main pages.

<?= $site->page('mediation')->textM()->kirbytext()->excerpt(100, 'words') ?>

Thanks in advance!!

Try this:

<?= $site->page('mediation')->textM()->excerpt(100, 'words')->kirbytext() ?>

Usually kirbytext()comes last in the chain. I have a feeling though that excerpt strips things out in order to count the words, so if it doesnt work, you can always just wrap it in a p tag.

<p><?= $site->page('mediation')->textM()->excerpt(100, 'words') ?></p>
1 Like

This will throw an error, because then you call kirbytext on string.

Putting everything in p tags doesn’t preserve the original tags either.

The best way to have full control is using a separate field with a short summary.

If you want to preserve HTML tags, you would have to use the underling str::excerpt() method from the toolkit. However, is doesn’t support words.

I’d probably create a custom field method.

1 Like

@maxlennarts I made a little plugin for this yesterday. See here.

1 Like