XF 2.2 Need help with template code, please

Robert9

Well-known member
<xf:select name="gender" value="{{ $filters.gender ? $filters.gender : $xf.visitor.gender}}">

but i need something like

if filter, then filter, elseif visitor=men =>woman, else man

Should i use the usual xf:if, else, end or can i shorten it like above somehow?
 
Yes, shure, but i need something like:

{{ $filters.gender ? $filters.gender : ($xf.visitor.gender == '0' ? 1: 0) }}

or something like

{{ $filters.gender ? $filters.gender : opposite_of($xf.visitor.gender) }}

while $xf.visitor.gender is 0/1

or whatever changes 0 to 1 and 1 to 0
 
If there is a filter, set the filter.
If there is no filter, set the other gender.
Because probably boys want to look for girls and girls want to look for boys.
 
I seach for users with xf_user.gender and filters. m=0, f=1
If there is a filter set, the form should be filled with this filter.
If no filter is set, the filter should be set with the other gender from the view of $visitor

Normally i would write:
Code:
<xf:if is = "$filters.gender">
    $filters.gender
<xf:else/>
    <xf:if is = "$xf.visitor.gender == '0'">
        1
    <xf:else/>
        0
    </xf:if>
</xf:if>
 
Dump the vars in the template to see if they are available.

That will confirm whether you can use them in conditional statements or not.
 
Thank you.
I want to know: is there a short way to write the long statement?
Can i nest the short code? Something like:

{{ $filters.gender ? $filters.gender : ($xf.visitor.gender == '0' ? 1: 0) }}

OR

is there anything "build in" to get "the other one" of a bool?

$bool=1
$x = function_to_get_the_other_value_of_a_bool($bool) = 0

$bool=0
$x = function_to_get_the_other_value_of_a_bool($bool) = 1
 
Top Bottom