Did creating a trimpath expression modifier not work?
https://code.google.com/p/trimpath/wiki/JavaScriptTemplateSyntax