Categories > TinyButStrong general >

How to have more than one comparison in single 'if'

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: leeladharan
Date: 2005-04-20
Time: 09:57

How to have more than one comparison in single 'if'

I need tbs to work as below
if(val == 'img/jpg' || val == 'img/gif' || val == 'img/png')
  {
     <img>
  }
else
  {
    <a>  Download </a>
   }

My Tbs code for single comparison is working fine . I need this to modify
which works as above logic

[doc.mimeType;if [val]==image/jpeg;then <img src = "./files/doc/events/[doc.file]" width = "100" height = "100">;else <a class="colorLink" href="../files/doc/events/[doc.file]" target="_BLANK"><b>[var.download]</b></a>]
By: Skrol29
Date: 2005-04-20
Time: 13:11

Re: How to have more than one comparison in single 'if'

Hi,

Parameter 'if' doesn't have an OR operator. So the best way is to use a custom function with parameter 'onformat'.
function f_file_type($FieldName,&$CurrVal) {
  if (($CurrVal=='img/jpg') || ($CurrVal=='img/gif') || ($CurrVal=img/png)) {
    $CurrVal = 'img';
  } else {
    $CurrVal = 'link';
  }
}

And the field can be something like this:
[doc.mimeType;onformat=f_file_type;if [val]=img;then ...; else ...]
By: leeladharan
Date: 2005-04-21
Time: 08:04

Re: How to have more than one comparison in single 'if'

Thank You Skrol29 the code u sent is working fine