sdepold / jquery-rss

An easy-to-use rss plugin for jquery with templating.
MIT License
453 stars 143 forks source link

Truncate {title} objects by chatacter number #69

Closed Castellanox7 closed 9 years ago

Castellanox7 commented 9 years ago

Good morning,

Is there any support for wanting to truncate the {titles} retrieved by the RSS feed?

For example, "This is a Test Post", becomes "This is a Test..."

Thank you.

sdepold commented 9 years ago

Good morning. You basically want this:

$('#foo').rss({
  entryTemplate: '<p>{truncatedTitle}</p>',
  tokens: {
    truncatedTitle: function (entry, tokens) {
      return tokens.title.slice(0, 5) + '...';
    }
  }
});

This will give you the first 5 chars of the title.

Castellanox7 commented 9 years ago

Awesome. Thanks, Sd!