Excerpt Issues in Kirby 3

In Kirby 3 I was getting errors for the below chunk of code that would halt the page load as I was trying to convert from Kirby 2.

echo excerpt($project->text(), 50, 'words')

If I simply put str:: in front of it the call would work, but it changed from word count to char count (which I see the change in documentation) and it also includes markdown whereas before it just rendered the text (for example if a link was in that text) as just text.

Any good way to get this back to its original output?

Also maybe this should be noted on the update page as it breaks the page…

AFAIK this wouldn’t work in K2 neither (at least not in recent versions). See https://k2.getkirby.com/docs/toolkit/api/str/excerpt

There is however a function in the old K2 class that might help you to come up with something that would enable you to build something like this: https://github.com/getkirby-v2/toolkit/blob/b6457bab41d347d5ae4ed6b92244935e6dfed919/lib/str.php#L293

I’m on the below version, that’s why I found it odd that it broke in 3.

Toolkit version: 2.5.12
Kirby version: 2.5.12
Panel version: 2.5.12

Hm, that’s the latest version.

I can’t find any reference in the source to words though: https://github.com/getkirby-v2/toolkit/blob/b6457bab41d347d5ae4ed6b92244935e6dfed919/lib/str.php#L363

The excerpt helper with the word parameter does exist in Kirby 2. It has been removed from Kirby 3, though.

I don’t know how well that function worked, as far as I recall, there were problems with word count in non-English languages, maybe that’s the reason why it was removed, not sure.

It should be pretty easy to create your own replacement function in a plugin, though, using the old code. I’ll create an issue to add this to the documentation.

1 Like

@andrewthread Alternatively, there is my Chopper plugin for Kirby 2 which I’m looking to upgrade to K3 very soon once I’ve figured out the new plugin stuff. I don’t think it will take much, I just haven’t had the time yet. Feel free to have a stab at it if you cant wait a little.

Chopper doesn’t work for me in K3, never did, sadly :confused:

Strange… worked last time I used it… can give you me any more details?

Well, I even opened an issue on Github, like months ago, but here goes:

  1. I download it and put it in site/plugins/chopper
  2. I insert <?= $page->text()->chopper(20) ?> in my template file
  3. I get the full text (~ 300 words)

Let’s discuss this over at Github, shall we? :slight_smile:

I was thinking more Kirby version and PHP version… but hey… github it is… :walking_man:

@S1SYPHOS Looks like it might be a PHP 7.3 issue… works fine on 7.1. Unfortunately my local server just got upset switching to 7.3. If i can get it going, i’ll see what the problem could be.

Well… i got PHP 7.3.2 running, and used the plugin in a fresh starterkit (3.1.3) and it works fine. @S1SYPHOS I got nothing… i guess its something in your current project.

<?= $page->text()->chopper(50, 'words', '→') ?>