Excerpt issue upgrading from k2 to k3

I’m upgrading from Kirby 2 to Kirby 3 and am getting hung up on an issue with excerpts.

What I had in k2:
First set up $heroPost to grab the last blog written

<?php $heroPost = $pages->findBy('uid', 'blog')->children()->listed()->flip()->first() ?>

Then I had this for an excerpt:
<?php echo excerpt($heroPost->text(), 200) ?>

When I tried to convert that to Kirby 3 excerpt, $field->excerpt() | Kirby CMS

<?php $heroPost->excerpt(int $chars = 200, bool $strip = true, string $rep = ' …') ?>

I get an error in debug: syntax error, unexpected ‘$chars’ (T_VARIABLE), expecting ‘,’ or ‘)’

Obviously I’m missing something simple here, any help is appreciated.

There are three issues here:

  1. $heroPost is (hopefully) a page object, not a field object (but excerpt is a field method)
  2. You don’t call a method with its signature, but with values for the parameters
  3. Your code line is missing an echo statement

Correct:

<?= $page->text()->excerpt(); ?>

This will use the method with its default values. If you want to change any of the parameters, e.g. the excerpt length, i.e. without the type hint and the name of the parameter:

<?= $page->text()->excerpt(300); ?>
<?= $page->text()->excerpt(300, false); ?>
<?= $page->text()->excerpt(300, false, '…'); ?>

Thanks! That makes sense now. All fixed. I appreciate the help.