TopShelfCraft / Wordsmith

A plugin for Craft CMS to help you manage and manipulate text.
Other
30 stars 20 forks source link

How to use readTime filter with Matrix field? #53

Closed Saboteur777 closed 2 years ago

Saboteur777 commented 2 years ago

I am trying to use the readTime filter with matrix fields, but I can't make it work, as entry | readTime(rate=140, minimum=2) return 2 every time (sure, because without minimum it would return 1). I have also tried entry.matrixField, but it did not work either.

michaelrog commented 2 years ago

Most Wordsmith functions, including readTime, operate on a string input. If you pass in an Entry or MatrixBlockQuery object instead of a string, PHP will try to cast the object as a string (using its __toString() method, if there is one). That probably won't be very useful. (IIRC, the _toString() of an entry just returns its title.) To estimate the total read-time of an entry, you need to first get the total text content, by rendering the fields into meaningful string values.