Panel - Displaying the number of characters of each page

Hi, I wonder if there is a way to display for each page in the panel the number of chars of the page (one or more fields considered). Expecially when using the blocks field.

thanks
Francesco

That’s certainly possible, but the question is what exactly you want to count.

Most of the times, the content of a specific field.

For a blocks field, you can probably do something like this:

$blocks = $page->text()->toBlocks()->toHtml();
dump(Str::length(strip_tags($blocks)));

For other fields, there is a field method called length()

var_dump($page->text()->length());

If you call that on a blocks field, it probably counts every character stired in that field, which wouldn’t make sense. But also for textarea, it would count Kirbytags, HTML if present etc.

Thank you @pixelijn but what I don’t know is how to expose inside the panel the value. I need the author of the post to be aware of how long his article is.

In real time? Like, while he’s typing?

After the page is saved