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.
I’m displaying the excerpt this way
`<?= $article->text()->excerpt('100') ?>`
with my blueprint as such
label: Article Content
You have to output the editor field with the
<?= $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') ?>
I tried the solution given but it outputs this error:
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
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) ?>">
<?= $column->blocks() ?>
<?php endforeach ?>
<?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
But whether this makes sense, depends on the content of your layouts…
I’ll play with it, thanks very much