Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 1.01 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Limit the number of characters rendered by a Mustache.js tag
  2. template = "<li>{{my_tag}}</li>"
  3.  
  4. data = {
  5.     "my_tag" : "A very long string that needs to be abbreviated to fit into the available space."
  6. }
  7.        
  8. template = "<li>{{#limitLength}}{{my_tag}}{{/limitLength}}</li>"
  9.  
  10. data = {
  11.     "limitLength" : function() {
  12.         return function(text) {
  13.           return text.substr(0,10) + '...';
  14.         }
  15.       },
  16.     "my_tag" : "A very long string that needs to be abbreviated to fit into the available space."
  17. }
  18.        
  19. data = {
  20.     "limitLength" : function() {
  21.         return function(text) {
  22.           return Mustache.to_html(text,data).substr(0,10) + '...';
  23.         }
  24.       },
  25.      "my_tag" : "A very long string that needs to be abbreviated to fit into the available space."
  26. }
  27.        
  28. data = {
  29.     "limitLength" : function() {
  30.         return function(text, render) {
  31.           return render(text).substr(0,10) + '...';
  32.         }
  33.       },
  34.      "my_tag" : "A very long string that needs to be abbreviated to fit into the available space."
  35. }