• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 1.4 Gender Conditionals

Amaury

Well-known member
#1
A while ago I created a phrase to use for status updates in the news feed (by default, there is no phrase and it just shows the username and the status itself). I just used their in the phrase, but is there a way I can make it display the appropriate gender pronoun as follows:
  • His (if the person has male as their gender)
  • Her (if the person has female as their gender)
  • Their (if the person has selected no gender)

upload_2015-4-9_12-8-3.png
 

Liam W

Well-known member
#2
Yes - the gender is stored in the gender field.

So, this template content (news_feed_item_user_status) would work:

HTML:
<h3 class="description"><xen:username user="$user" class="primaryText" /> <xen:if is="{$user.gender} == 'male'">{xen:phrase updated_his_status}<xen:elseif is="{$user.gender} == 'female'" />{xen:phrase updated_her_status}<xen:else />{updated_their_status}</xen:if> <em>{xen:helper bodyText, $status.new}</em></h3>
Liam

Edit: Drat, one problem :) Fixed now though, the code above is tested.
 

Amaury

Well-known member
#3
Yes - the gender is stored in the gender field.

So, this template content (news_feed_item_user_status) would work:

HTML:
<h3 class="description"><xen:username user="$user" class="primaryText" /> <xen:if is="{$user.gender} == 'male'">{xen:phrase updated_his_status}<xen:elseif is="{$user.gender} == 'female'" />{xen:phrase updated_her_status}<xen:else />{updated_their_status}</xen:if> <em>{xen:helper bodyText, $status.new}</em></h3>
Liam

Edit: Drat, one problem :) Fixed now though, the code above is tested.
I'll give it a try when I'm back on my desktop. Thanks!
 
#6
To be honest I don't know why this isn't already standard in Xenforo. I mean it's such a simple thing for the devs to include that would make XF better for everyone who uses it.
 
#10
Using news_feed_item_user_status doesn't appear to work where we want to make this change, we found that news_feed_item_profile_post_insert is the necessary template. However $user.gender doesn't seem to work in this template, so we're stuck trying to figure out how we can distinguish gender here.
 

Brogan

XenForo moderator
Staff member
#12
Adding this to the template will show what is available for the user record:
Code:
{xen:helper dump, $user}
In this case just user_id and username are available in the news_feed_item_profile_post_insert template.

Custom development would be required to make the gender available in the record.