[Templates] substr vmethod

Sergey Martynoff sergey@martynoff.info
Wed, 9 Aug 2006 19:49:07 +0400


> > I thought I'd seen someone mention a substr vmethod
> > on this list.  I can't find anything about substrings
> > in the manual.
> > 
> > I need to display the first 34 chars. of a template
> > variable.  Is there some way to do that?
> 
> Hackish, but should work:
> 
>   [% var.chunk(34).0 %]

It is not too effective, I guess. The 'substr' vmethod works well:

[% str.substr(0, 34) %]


There also is nice 'trucate' filter, it trucates the string and appends it
with '...':

[% str | truncate( 34 ) %]

To avoid '...' appending, use:

[% str | truncate( 34, '' ) %]


-- 
Sergey Martynoff