Skip to content
This repository was archived by the owner on Feb 11, 2021. It is now read-only.

Add excerpt() function to editor #159

Closed
GiantCrocodile opened this issue Nov 7, 2019 · 6 comments
Closed

Add excerpt() function to editor #159

GiantCrocodile opened this issue Nov 7, 2019 · 6 comments
Labels
type: feature ⭐️ Request or idea for a new feature
Milestone

Comments

@GiantCrocodile
Copy link

I would like to convert this line easily from textarea to editor:
$article->text()->html()->excerpt(300)

Right now, it seems that excerpt() isn't supported. A workaround seems to be this:
https://forum.getkirby.com/t/excerpt-for-editor-field/15970

@nilshoerrmann
Copy link

You can do $article->text()->toBlocks()->first()->toField()->excerpt(300).

@GiantCrocodile
Copy link
Author

GiantCrocodile commented Nov 7, 2019

This would only work with 300 chars if the first block contains those 300 chars, not the first x blocks summed together, right @nilshoerrmann? I think the excerpt() method works with 300 chars however they are organized/structured (simply because it's just one field with no structure at all).

Edit: It might work out to do $article->text()->blocks()->toField()->excerpt(300) or something similar. I have to give it a try later on.

@nilshoerrmann
Copy link

Edit: It might work out to do $article->text()->blocks()->toField()->excerpt(300) or something similar. I have to give it a try later on.

I think the method is not available on the full blocks collection, only on a single block. But I haven't checked.

@GiantCrocodile
Copy link
Author

Works:
$article->text()->blocks()->first()->toField()->excerpt(300)

Not working:
$article->text()->blocks()->toField()->excerpt(300)

The toField() fails on blocks() and thus excerpt is called on null.

@nilshoerrmann
Copy link

That's what I thought. Should not be to difficult to have this available on the blocks collection as well.

@bastianallgeier bastianallgeier added the type: feature ⭐️ Request or idea for a new feature label Nov 18, 2019
bastianallgeier added a commit that referenced this issue Nov 20, 2019
@bastianallgeier
Copy link
Member

$article->text()->blocks()->excerpt() is now available.

bastianallgeier added a commit that referenced this issue Nov 26, 2019
@bastianallgeier bastianallgeier added this to the 1.0.1 milestone Nov 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: feature ⭐️ Request or idea for a new feature
Projects
None yet
Development

No branches or pull requests

3 participants