Template talk:User Current Age

The UESPWiki – Your source for The Elder Scrolls since 1995
Jump to: navigation, search

Age Categories[edit]

I had proposed the idea of adding broad age categories (e.g. "Users in their twenties") to this template if people wanted them, but there was no support and a few detractors. I had no opinion one way or the other, but since I think the implementation I had thought of was elegant, I'm leaving it here against any future decision to add those categories. To do so, add the following code to the template after the last {{#local:years...}} declaration:

{{#local:agecat|{{#switch:{{#expr:
({{{years}}}>0) +
({{{years}}}>=13) +
({{{years}}}>=20) +
({{{years}}}>=30) +
({{{years}}}>=40) +
({{{years}}}>=150)}}

|0|6=                      <!-- Users with ages 150 or greater, or 0 and under do not get categorized -->
|1=Users who are children
|2=Users in their teens
|3=Users in their twenties
|4=Users in their thirties
|5=Users in their forties
}}}}
...
{{#if:{{{agecat|}}}|{{Userbox Category|{{{agecat}}}}}}}

Notes:

  • This is based on this version of the template and may not apply in the event of substantial rewrites.
  • I've only given up to forties in my example, but this could be extended to include additional groupings at need.

The technique takes advantage of the fact that a boolean expression such as (28>0) will evaluate to either 0 if false or 1 if true. It simply adds 1 for each statement that is true about the age provided, coming up with which group the user belongs in. Then it uses a switch statement based on that number to name the group. Robin Hoodtalk 23:28, 6 August 2010 (UTC)