Instead of trying to change the title after rendering it, change it as shown.
Pass the maxlength variable to your template, and then:
<script type="text/template" id="tpl_PhotoListItemView"> <div class="photo_stats_title"><%= title.substr(0,maxLength) %></div> </script>
If title.length less than maxlength, the entire line will be displayed. If it is larger, only the first characters of maxlength are maxlength .
Alternatively, simply copy the maximum length of the title into the .substr() call
If you need to perform more complex truncation (for example, adding "..." to truncated headers), you better change the header before displaying the template by passing the truncated version of the header to the template
Another option is to override Model.parse(response) by creating a shortTitle attribute on the model; that way it is always available when you work with a model
source share