Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Option to display gender on user profile page

edited September 2010 in Vanilla 2.0 - 2.8
On signup vanilla asks a user their gender but this isn't displayed on the user profile pages by default. Is there an option somewhere on the dashboard to display it?
Tagged:

Comments

  • That's a good point!
  • edited September 2010
    That's a good answer!
  • Hmmm.. can a simple php line be inserted to the profile page?
  • I bet it gets stored in the database, so a php command that draws from that would need to be added from the profile page... eazy breezy if you know how :p
  • how to show in user profile gender? or bottom of user avatar
  • how to show in user profile gender? or bottom of user avatar

    Either would be fine.
  • LincLinc Admin
    FYI, it's actually used by the activity statements so it knows to use he/she in them.
  • It can be done by adding

    <?php echo T('Gender'); ?>
    <?php echo ($this->User->Gender); ?>

    to userinfo.php

    gender is stored in the database as a lower case "m" or "f" so I am guessing more code would need to be added to make it display "male" or "female". I have no idea what that would look like.
  • To accomplish that the second line could become:

    <?php echo ($this->User->Gender == 'm') ? 'Male' : 'Female'; ?>
  • To accomplish that the second line could become:

    <?php echo ($this->User->Gender == 'm') ? 'Male' : 'Female'; ?>

    Thanks Lincoln! works like a charm.
  • Lincoln said:
    To accomplish that the second line could become:

    <?php echo ($this->User->Gender == 'm') ? 'Male' : 'Female'; ?>

    Will something other than a ternary operator work?
    I want to be able to have "entities" that represent groups.
    I have created another "gender" which is g for group - some of the rendered sentences look VERY odd.
    Can't see that a switch-case would work.

  • peregrineperegrine MVP
    edited May 2012

    Of course you would have to find all the tests in all the programs and modify the gender conditional everywhere.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • peregrineperegrine MVP
    edited May 2012

    you can do anything you want for a conditional if then else, if than elseif, why wouldn't switch-case work??

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • edited May 2012

    I was thinking of switch-case not working in a one line statement as you have in /library/core/class.format.php.

    EG $Gender = T($Activity->ActivityGender == 'm' ? 'his' : 'her');.

    I have used:

    switch ($Activity->ActivityGender){ case "m": $Gender = "his"; break; case "f": $Gender = "her"; break; default: $Gender = "their"; }
    And...

    switch ($Activity->ActivityGender){ case "m": $Gender2 = "he"; break; case "f": $Gender2 = "she"; break; default: $Gender2 = "they"; }

    Need to have a play around to see if it is performing as expected.

  • edited May 2012

    I want to place an associative array somewhere that can be used globally to convert m,f,t to Male,Female,Transvestite as required.

    I have done this in applications/dashboard/views/modules/userinfo.php....

    `
    $GenderArray = array('m'=>'Male', 'f'=>'Female', 't'=>'Transvestite');

    <dt class="Name"><?php echo T('Gender'); ?></dt><dd><?php while(list($key,$value) = each($GenderArray)) {if ($key == $this->User->Gender) {echo $value; }} ?></dd></dt>
    `

    ...but don't want to place it on every page where it might be required. That would be silly.
    (BTW will code this a bit better later on)

    Am still getting grips with the programming approach of this system so they may be a more logical mechanism than an associative array.

    If this array is best strategy then where best to place it?
    Root index.php?
    bootstrap.php
    a config file?

  • edited November 2017

    @Linc said:
    To accomplish that the second line could become:

    <?php echo ($this->User->Gender == 'm') ? 'Male' : 'Female'; ?>

    I know I'm replying to a post several years old, however, I think the following code is more correct, since the database has 3 states. u, m and f...

    <dt"><?php echo T('Gender'); ?></dt>
    <dd"><?php
    if ($this->User->Gender == 'u') {
        echo "Unspecified";
    } elseif ($this->User->Gender == 'm') {
        echo "Male";
    } else {
        echo "Female";
    }
    ?></dd>
    
  • It will be hard to decide what is "more correct", since there normally are a few ways to solve problems in Vanilla. I would like to throw in my opinion :wink:

    I see two fields for improvement: translation and universal usage.

    Let's assume you have built a great theme with that info as an enhancement and I as a German would like to use that. So instead of reading "male" I would prefer to translate that to "männlich". By now I would have to change that directly in your theme.
    Just yesterday I read a headline about an "intersexual" person that doesn't like to be bound to the choices m, f, u (but don't ask me in which context). So what if Vanilla extends that Gender field to include an "i"? An edge case, I know, but who can tell what the future will bring? I would have to change that theme again to include an "i" option. The result will be a monster:

    <dt><?php echo t('Gender'); ?></dt>
    <dd>
    <?php
        if ($this->User->Gender == 'm') {
            echo t('male');
        } elseif ($this->User->Gender == 'f') {
            echo t('female');
        } elseif ($this->User->Gender == 'i') {
            echo t('intersexual');
        } else {
            echo t('unspecified');
        }
    ?>
    </dd>
    

    You can try switch to make it a little less dirty:

    <dt><?php echo t('Gender'); ?></dt>
    <dd>
    <?php
    switch ($this->User->Gender) {
        case 'f':
            echo ('female');
            break;
        case 'm':
            echo t('male');
            break;
        case 'i':
            echo t('intersexual');
            break;
        default:
            echo t('unspecified');
    }
    ?>
    </dd>
    

    But that's not elegant nor short, either. I simply would prefer it for the added whitespace which makes it more readable.

    Instead of using that much logic in the template, I would prefer the intelligence happen elsewhere. At least we only want to display the gender here and we really don't care about the content.
    I would solve the above by using the following code in the template:

    <dt><?= t('Gender') ?></dt>
    <dd><?= t('Gender.'.$this->User->Gender) ?></dd>
    

    That way we reduce the output to a translation code and the logic that happens is, that the possible values (how many that may be) must exist in the translation file.
    You would have to include a locale file which translates "Gender.m", "Gender.f", "Gender.u" and everybody would be able to override that in their own /conf/locale.php file. If future will bring another option, you can simply include that by adding another translation to your locale file.

Sign In or Register to comment.