On 20/04/11 12:15, Jacob Rask wrote: > Is there some way to use, or replace, OR with something that handles values of > 0? The following code: > > title = "0"; > > title or 'untitled'; > > will print 'untitled'. > > I could use: > IF title.defined; title; ELSE; 'untitled'; END; > or > IF title.length> 0; title; ELSE; 'untitled'; END; > > but the "or" operator is very useful. How would you do it? > > /Jacob
As far as I am aware, TT doesn't have a defined-or operator, so instead, you could try the conditional (or ternary) operator: [% title = '0' %] [%# Prints <p>0</> %] <p>[% title.defined ? title : 'untitled' %]</p> [% title = '' %] [%# Prints <p></p> %] <p>[% title.defined ? title : 'untitled' %]</p> Alternatively, you could use 'length' instead of 'defined' to catch empty strings: [% title = '0' %] [%# Prints <p>0</> %] <p>[% title.length ? title : 'untitled' %]</p> [% title = '' %] [%# Prints <p>untitled</p> %] <p>[% title.length ? title : 'untitled' %]</p> Regards, Mike _______________________________________________ templates mailing list [email protected] http://mail.template-toolkit.org/mailman/listinfo/templates
