2

Any way to show the total word count in real-time to authors while they are writing an entry that has multiple blocks?

I don't need per-block word count ... I need total word count shown in real-time.

3 Answers 3

1

What you want to achieve is not an easy task because you would have to hook into many different events to recognize new blocktypes.

The fastest and easiest method would be to use this plugin as the base of your own https://github.com/mmikkel/CpFieldLinks-Craft/blob/master/README.md. You can edit the init function to show the script for everyone and not just administrators. Then you use the plugins Javascript function as your base script https://github.com/mmikkel/CpFieldLinks-Craft/blob/master/source/javascripts/CpFieldLinks.js and change the editFieldBtn template to display not the handle of your field but a custom variable. This variable will be the total word count.

You have to select all your needed fields with jquery (inspect the html in order to find out what selectors you can use) and use a word count script.

I`ve created something similar a few months ago and did the same. It was relatively easy compared to do all the work from zero

1

You'll need to add a plugin like this one from Lindsey DiLoreto that allows you to insert your own javascript into the CP. Then you'll need to write some javascript that counts up each word in a textarea input for each block. I'm sure stackoverflow has several answers on how to do that. Keep in mind Craft already has jQuery installed if you choose to use it.

1

For rendered outputs, you can use Wordsmith's Text Statistics & Readability module to output integers needed. Also comes with some useful backend filters / tests.

For seeing word/character count in the backend while editing, set the plain text field to "Redactor" and use a Custom Redactor Config to remove the formatting buttons and turn on the "Counter" plugin:

{ "plugins": ["counter", "limiter"], "buttons": ["html"], "formatting": [""], "limiter": 160, "cleanOnEnter": true, "pastePlainText": true }

Note: the above "limiter" plugin will remove the ability to paste into the field with ctrl+v though rightclick+paste still works (and will exceeds the limiter amount). Also, this may output a <p></p> but you can use Twig striptags to strip all tags from the field: entry.fieldname|striptags

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.