I want to limit number of characters while fetching content from a collection field

I am fetching data from a collection. For a single field (it has large amount of characters), i want to limit the number of characters like (200 or 250).
I don’t want to put any condition on the Cms backend, just want to put this condition while fetching the data and display it on frontend.

Please help…


Hey @Romey_Gill Try this
<script> $(".your class goes here").each(function () { //replace 50 with your desired number of character's var truncated = $(this).text().substr(0, 50); //checking and replacing with "..." length is less than your desired number of character's $(this).text(truncated + (truncated.length < 50 ? "" : "...")); }); </script>

Hope it helps :peace_symbol:

1 Like