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
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:
1
Comments
Either would be fine.
<?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.
<?php echo ($this->User->Gender == 'm') ? 'Male' : 'Female'; ?>
Thanks Lincoln! works like a charm.
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.
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.
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.
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.
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?
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...
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
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:
You can try
switch
to make it a little less dirty: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:
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.