Reputation: 483
Is there a way to mask the output of YesNoFormat() so that instead of 'yes' and 'no' it displays 'active' and 'inactive'.
<cfset currstatus = YesNoFormat(usrStatus)> //Returns Yes. I want this to return active
Before displaying i can do a if/else check: if "Yes" display "active" else display "inactive". but I want to avoid this as I have to do this in lot of places so just want to reach out to the community if their is any masking capability/technique available for this function. If not is there any alternative. Comment if you need more details
Upvotes: 2
Views: 236
Reputation: 11702
You can't do YesNoFormat(value, [maskvalue1, maskvalue2])
but you can do YesNoFormat(value) ? "maskvalue1" : "maskvalue2"
and since value
must be a number or boolean you end up with
((value) ? "maskvalue1" : "maskvalue2")
in your case
<cfset currStatus = ((usrStatus) ? "active" : "inactive") />
Upvotes: 3
Reputation: 20105
YesNoFormat()
unfortuantely doesn't allow to output different strings.
If you need that functionality in a lot of places, you should therefore create your own function like this:
<cffunction name="boolToString" returntype="string">
<cfargument name="boolVar" type="boolean" required="yes">
<cfreturn boolVar ? "active" : "inactive">
</cffunction>
Upvotes: 3
Reputation: 2287
Single line version of the if/else statement:
<cfset currstatus = usrStatus ? "active" : "inactive">
Upvotes: 8
Reputation: 63
the only way i can see is to use a if statement.
<cfif usrStatus>
<cfset currstatus = "active">
<cfelse>
<cfset currstatus = "inactive">
</cfif>
Hope this helps.
Upvotes: 1