Gossamer Forum
Home : Products : Gossamer Forum : Discussion :

Re: [Franco] <%if var contains ... or <%if var like ...

Quote Reply
Re: [Franco] <%if var contains ... or <%if var like ... In reply to
You are changing a specific letter in one case, but it won't work in other ones.

A more general solution might be to create a global "contains"

<%contains (<%var%>, <%string%>)%>

This returns a tag CONTAINS which is True or False depending on the compare.
Code:
sub {
my ($var, $str) = @_;
m|$var|$str|gi && return ( {CONTAINS=>'True'} );
return ( {CONTAINS=>'False'} );

}


Not sure if this works, haven't tested it, but the idea is there.

Then in your templates, you'd use

<%if CONTAINS eq 'True'%> do something <%endif%>

The value of CONTAINS will always be the most recent test, so you can reuse this. You could also pass in the return variable, so you could use multiple tests, keeping the value of each for subsequent use.

There are still some bugs using the value of a function in a test, so you need to use this long form to get the value of the subroutine into a variable.




PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Subject Author Views Date
Thread <%if var contains ... or <%if var like ... Franco 3316 Aug 18, 2003, 12:20 AM
Thread Re: [Franco] <%if var contains ... or <%if var like ...
Alex 3246 Aug 18, 2003, 2:02 PM
Thread Re: [Alex] <%if var contains ... or <%if var like ...
Franco 3265 Aug 19, 2003, 9:19 AM
Thread Re: [Franco] <%if var contains ... or <%if var like ...
Franco 3230 Aug 19, 2003, 6:41 PM
Thread Re: [Franco] <%if var contains ... or <%if var like ...
pugdog 3224 Aug 21, 2003, 8:31 AM
Thread Re: [pugdog] <%if var contains ... or <%if var like ...
Franco 3208 Aug 21, 2003, 8:46 AM
Thread Re: [Franco] <%if var contains ... or <%if var like ...
Jagerman 3211 Aug 21, 2003, 1:40 PM
Thread Re: [Jagerman] <%if var contains ... or <%if var like ...
Jagerman 3203 Aug 21, 2003, 1:51 PM
Post Re: [Jagerman] <%if var contains ... or <%if var like ...
Franco 3182 Aug 21, 2003, 9:18 PM