XF 1.4 Gender Conditionals

Amaury

Well-known member
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.webp
 
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.
 
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!
 
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.
 
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.
 
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.
 
Back
Top Bottom