Andy Wardley wrote:
Stuart Johnston wrote:

Since my problem requires adding the suffix regardless of length,

[...]


I'm not sure what example you are referring to but my problem is that I need the complete, final string to be less than a certain length so I can't simply use "_".


Is it not as simple as truncating the string to 18 characters and then adding the suffix?

[% string.truncate(18).append('_colname_seq') %]


That won't work because 'colname' is also dynamic.


You could turn it into a MACRO if you prefer:

[% USE String;

     MACRO truncadd(text, suffix) BLOCK;
        length = 30 - suffix.length;
        String.new(text).truncate(length).append(suffix);
     END;
 %]

[% truncadd('verylongtablenameindeed', '_column_seq') %]

=> verylongtablenamein_column_seq

I like that, except my production system will probably be running an older version (Debian package) that doesn't have the String plugin and I'd rather avoid upgrading it if I can. I think what I have will work fine.



Thanks, Stuart Johnston


_______________________________________________ templates mailing list [EMAIL PROTECTED] http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to