# Shortening text in repeater

**URL:** <https://forum.wixstudio.com/t/shortening-text-in-repeater/16595>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [February 19, 2019, 12:58am UTC](https://forum.wixstudio.com/t/shortening-text-in-repeater/16595 "2019-02-19T00:58:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![witty](https://avatars.discourse-cdn.com/v4/letter/w/0ea827/32.png) [@witty](https://forum.wixstudio.com/u/witty)\
**Post date:** [February 19, 2019, 12:58am UTC](https://forum.wixstudio.com/t/shortening-text-in-repeater/16595/1 "2019-02-19T00:58:31Z")

</div>

I have a text element #text82 in a repeater #repeater2, connected to a dataset #dataset1. In this text element, I want to only show a max length of character (max 20 characters) from the collection text field (collection field name is “News Content-English” and field key is newsContentEnglish, so #text82 is connected to “News Content-English” in repeater), because the original full text in way too long to show in this repeater. I just want visitors to have a shortened version and then click “Read more” to go to the corresponding dynamic page where they can read full text.

I have inserted this code in the repeater page code, and the text is not getting truncated/shortened when I preview page, so can someone please correct the code please. I am not a developer, so take it easy 😉 Thanks!  
(The page is not live, as I don’t want to publish until I get this issue sorted out.)

$w.onReady( **function** () {  
$w(“#dataset1”).onReady( **function** () {  
**const** shortTextLength = 20;  
**let** fullText;  
**let** shortText;  
$w(“#repeater2”).forEachItem(($w, item) =\> {  
fullText = $w(‘#dataset1’).getCurrentItem().definition;  
**if** (fullText.length \<= shortTextLength) {  
$w(‘#text82’).text = fullText;

```
        } **else** { 
            shortText = fullText.substr(0, shortTextLength) + "..."; 
            $w('#text82').text = shortText; 
        } 
    }) 
}) 

```

})

---

<div class="post-metadata">

**Author:** ![sonudilse143](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/sonudilse143/32/26912_2.png) [@sonudilse143](https://forum.wixstudio.com/u/sonudilse143)\
**Post date:** [February 21, 2021, 10:40am UTC](https://forum.wixstudio.com/t/shortening-text-in-repeater/16595/2 "2021-02-21T10:40:30Z")

</div>

Hi,  
get code Shortening text in repeater.  
Used and verified.

$w.onReady(function () {  
$w(“#dataset1”).onReady(function () {  
$w(‘#repeater1’).onItemReady( ($item, itemData, index) =\> {

```
        let theItem = itemData.longDescriptionProduct (this is your dataset field key)             
        var shortDescription = theItem.substr(0, 50) ; 
    $item('#description').text = shortDescription + "..." ; 
        } ); 
    }) ; 
}) ;

```
