Blog Excerpt with Editor plugin - need help

Please forgive, this may be simple, but I’m a noob. My blog excerpts are not displaying properly. I implemented the Kirby Editor plugin, which is working well. But on my Articles page i’m getting additional text in the excerpt. see image below.

Screen Shot 2020-02-29 at 11.14.47 AM

I’m displaying the excerpt this way

 `<?= $article->text()->excerpt('100') ?>`

with my blueprint as such

text:
    label: Article Content
    type: editor
    size: large
    files: page.images
    image:
      cover: true
    uploads: textarea-upload

thanks.

You have to output the editor field with the blocks() method

<?= $article->text()->blocks() ?>

Then you should be able to string excerpt() onto it:

<?= $article->text()->blocks()->excerpt() ?>

Yeah, ugh. It’s wierd. That was first thing I had tried like below… but was throwing an error. now it’s working. Not sure why. maybe I was using block() instead of blocks()

<?= $article->text()->blocks()->excerpt('100') ?>

Thank you!

I tried the solution given but it outputs this error:

InvalidArgumentException

The block type is missing

@GianlucaSavini Are you using the Editor plugin? Are 3.5.x with the blocks field?

Yes, I’m using 3.5.0 with the editor plugin.

the blueprint for the text field is

text:
type: layout

Then that’s not the Editor plugin, but the new layout field. The Editor plugin is not really compatible with Kirby 3.5.x (at least not at the moment).

There is no method to get an excerpt directly from the layout field. You would have to get the first layout element, then when you call toBlocks() on the first column, you could get an excerpt.

This is the standard code to display the contents of a layout field on the frontend:

<?php foreach ($page->layout()->toLayouts() as $layout): ?>
<section class="6-column-grid" id="<?= $layout->id() ?>">
  <?php foreach ($layout->columns() as $column): ?>
  <div class="column" style="--span:<?= $column->span(6) ?>">
    <div class="blocks">
      <?= $column->blocks() ?>
    </div>
  </div>
  <?php endforeach ?>
</section>
<?php endforeach ?>

So you first loop through the layouts, then the columns until you get to the blocks.

But of course, you can also fetch the first layout with

$layout = $layouts->first();

Then the first column:

$firstCol = $layout->columns()->first();

And then the blocks

echo $firstCol->blocks()->excerpt(200);

But whether this makes sense, depends on the content of your layouts…

I’ll play with it, thanks very much