Difference between revisions of "Template:GetMasterCategoryList"
(Not all Vocationals qualify for Technician Master) Tag: Undo |
|||
(29 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
<noinclude> | <noinclude> | ||
− | This template outputs a <nowiki> | + | This template outputs a list of language-appropriate category links separated by <nowiki>"%|%"</nowiki>. Each link indicates a Master Award to which an honor belongs. It was designed to be used by the honor_infobox template. The display names of the links are translated. |
− | ==Example== | + | ==Example== <!--T:2--> |
− | <nowiki>{{GetMasterCategoryList</nowiki><br/> | + | <div class="toccolours"> |
− | |category=Arts, Crafts and Hobbies<br/> | + | :<nowiki>{{GetMasterCategoryList</nowiki><br/> |
− | | | + | ::|category=Arts, Crafts and Hobbies<br/> |
− | |master2= | + | ::|master1=Wilderness<br/> |
− | }}<br/> | + | ::|master2=Conservation<br/> |
+ | :}}<br/> | ||
+ | </div> | ||
+ | <!--T:3--> | ||
{{GetMasterCategoryList | {{GetMasterCategoryList | ||
|category=Arts, Crafts and Hobbies | |category=Arts, Crafts and Hobbies | ||
− | | | + | |master1=Wilderness |
− | |master2= | + | |master2=Conservation}} |
− | ==Mechanics== | + | ==Mechanics== <!--T:4--> |
− | The output list is stored in a variable called ''mlist'' (master list) and that is emitted at the end of the template. | + | The output list is stored in a variable called ''mlist'' (master list) and that is emitted at the end of the template with <nowiki>{{</nowiki>#var:mlist}}. |
+ | <!--T:5--> | ||
It starts by looking at the {{{category}}} parameter and assigning a mlist to one of the category-based Master Awards. Not every honor category results in a Master Award, so the switch statement doesn't deal with all of the known categories. In other words, mlist may or may not be empty when we come out of the switch statement. | It starts by looking at the {{{category}}} parameter and assigning a mlist to one of the category-based Master Awards. Not every honor category results in a Master Award, so the switch statement doesn't deal with all of the known categories. In other words, mlist may or may not be empty when we come out of the switch statement. | ||
− | It then looks to see if the {{{ | + | <!--T:6--> |
+ | It then looks to see if the {{{master1}}} argument specified that the honor is part of some other Master Award, and if it is, it adds that to mlist. If mlist already has something assigned to it, the code will append mlist with a <nowiki><br/></nowiki> tag before appending the master award category. | ||
+ | The category link it actually adds will be <nowiki>[[</nowiki>Category:AY Honors/''some master award''/''language'']], where ''some master award'' is constructed by appending <nowiki>{{{master}}}</nowiki> to "Master Award". So we'd get for example, "Artisan Master Award". The ''/language'' part is added by the <nowiki>{{GetLangSuffix}}</nowiki> call. | ||
+ | |||
+ | Category links can display something other than the category name, and in our case, that's what we want to do. We don't want to see "Category", nor do we want to see the "AY Honors/" part of the category name. That's a file organization detail, not something to display. Further, the category name is in English, which will not do if the invoking page is not English. So instead, we grab the Localized name of the master award, by fetching it from <nowiki>{{:</nowiki>Localization:''English Name of Master Award''<nowiki>{{</nowiki>GetLangSuffix}}}}. | ||
+ | |||
+ | <!--T:7--> | ||
After the switch statement we have this:<br/> | After the switch statement we have this:<br/> | ||
− | <nowiki>{{#if:{{{ | + | <nowiki>{{#if:{{{master1|}}}|...</nowiki><br/> |
− | The goal of that statement is so that we can add a <nowiki><br></nowiki> to mlist if the {{{ | + | The goal of that statement is so that we can add a <nowiki><br></nowiki> to mlist if the {{{master1}}} parameter was provided. Then :<br/> |
<nowiki>{{#varexists:mlist|{{#vardefine:mlist|{{#var:mlist}}<br>}}}}</nowiki> | <nowiki>{{#varexists:mlist|{{#vardefine:mlist|{{#var:mlist}}<br>}}}}</nowiki> | ||
Which checks to see if we had assigned anything to mlist in the switch statement previously, and if we did, it redefines mlist (<nowiki>{{#vardefine:mlist...</nowiki>) by repeating the contents of mlist (<nowiki>{{#var:mlist}}</nowiki>) followed by the line break (<nowiki><br></nowiki>). It then repeats similar logic to append the category link to mlist:<br> | Which checks to see if we had assigned anything to mlist in the switch statement previously, and if we did, it redefines mlist (<nowiki>{{#vardefine:mlist...</nowiki>) by repeating the contents of mlist (<nowiki>{{#var:mlist}}</nowiki>) followed by the line break (<nowiki><br></nowiki>). It then repeats similar logic to append the category link to mlist:<br> | ||
− | <nowiki>{{#vardefine:mlist|{{#var:mlist}}[[:Category:AY Honors/{{{ | + | <nowiki>{{#vardefine:mlist|{{#var:mlist}}[[:Category:AY Honors/{{{master1}}} Master Award{{GetLangSuffix}}{{!}}{{Localize|{{{master1}}} Master Award}}]]}}</nowiki> |
+ | |||
+ | As with the category-based logic in the switch statement, we are dealing with localization here too using very similar logic (using <nowiki>{{GetLangSuffix}}</nowiki> to link to the correct category, and the <nowiki>{{:Template:Translation...}}</nowiki> magic) just as before. | ||
+ | |||
+ | It then repeats that logic using <nowiki>{{{master2}}}</nowiki>. | ||
+ | <!--T:8--> | ||
Note that the <nowiki>{{!}}</nowiki> template is used to output a | within the <nowiki>[[:Category...</nowiki> link so that we can indicate the text displayed as the link. The use of the <nowiki>{{!}}</nowiki> template is necessary to prevent the <nowiki>{{#vardefine...}}</nowiki> function from interpreting it as its own separator. | Note that the <nowiki>{{!}}</nowiki> template is used to output a | within the <nowiki>[[:Category...</nowiki> link so that we can indicate the text displayed as the link. The use of the <nowiki>{{!}}</nowiki> template is necessary to prevent the <nowiki>{{#vardefine...}}</nowiki> function from interpreting it as its own separator. | ||
− | </noinclude><includeonly>{{# | + | <!--T:9--> |
− | + | </noinclude><includeonly>{{#vardefine:mlist|}}{{#switch:{{{category}}} | |
− | | Arts, Crafts and Hobbies ={{#vardefine:mlist|[[:Category:AY Honors/Artisan Master Award{{ | + | | Arts, Crafts and Hobbies ={{#vardefine:mlist|[[:Category:AY Honors/Artisan Master Award{{GetLangSuffix}}{{!}}{{Localize|Artisan Master Award}}]]%{{!}}%}} |
− | + | | Outdoor Industries ={{#vardefine:mlist|[[:Category:AY Honors/Farming Master Award{{GetLangSuffix}}{{!}}{{Localize|Farming Master Award}}]]%{{!}}%}} | |
− | | Outdoor Industries ={{#vardefine:mlist|[[:Category:AY Honors/Farming Master Award{{!}}Farming Master Award]]}} | + | | Household Arts ={{#vardefine:mlist|[[:Category:AY Honors/Homemaking Master Award{{GetLangSuffix}}{{!}}{{Localize|Homemaking Master Award}}]]%{{!}}%}} |
− | | Household Arts ={{#vardefine:mlist|[[:Category:AY Honors/Homemaking Master Award{{!}}Homemaking Master Award]]}} | + | | ADRA ={{#vardefine:mlist|[[:Category:AY Honors/ADRA Master Award{{GetLangSuffix}}{{!}}{{Localize|ADRA Master Award}}]]%{{!}}%}} |
− | | | ||
− | |||
}} | }} | ||
− | {{#if:{{{ | + | {{#if:{{{master1|}}}|{{#varexists:mlist|{{#vardefine:mlist|{{#var:mlist}}}}}}{{#vardefine:mlist|{{#var:mlist}}[[AY Honors/{{{master1}}} Master Award{{GetLangSuffix}}{{!}}{{Localize|{{{master1}}} Master Award}}]]%{{!}}%}}}} |
− | {{#if:{{{master2|}}}|{{#varexists:mlist|{{#vardefine:mlist|{{#var:mlist}} | + | {{#if:{{{master2|}}}|{{#varexists:mlist|{{#vardefine:mlist|{{#var:mlist}}}}}}{{#vardefine:mlist|{{#var:mlist}}[[AY Honors/{{{master2}}} Master Award{{GetLangSuffix}}{{!}}{{Localize|{{{master2}}} Master Award}}]]%{{!}}%}}}}{{#var:mlist}}</includeonly> |
− | {{#var:mlist}} | ||
− | </includeonly> |
Latest revision as of 02:04, 28 September 2021
This template outputs a list of language-appropriate category links separated by "%|%". Each link indicates a Master Award to which an honor belongs. It was designed to be used by the honor_infobox template. The display names of the links are translated.
Example
- {{GetMasterCategoryList
- |category=Arts, Crafts and Hobbies
- |master1=Wilderness
- |master2=Conservation
- |category=Arts, Crafts and Hobbies
- }}
Artisan Master Award%|%Wilderness Master Award%|%Conservation Master Award%|%
Mechanics
The output list is stored in a variable called mlist (master list) and that is emitted at the end of the template with {{#var:mlist}}.
It starts by looking at the {{{category}}} parameter and assigning a mlist to one of the category-based Master Awards. Not every honor category results in a Master Award, so the switch statement doesn't deal with all of the known categories. In other words, mlist may or may not be empty when we come out of the switch statement.
It then looks to see if the {{{master1}}} argument specified that the honor is part of some other Master Award, and if it is, it adds that to mlist. If mlist already has something assigned to it, the code will append mlist with a <br/> tag before appending the master award category.
The category link it actually adds will be [[Category:AY Honors/some master award/language]], where some master award is constructed by appending {{{master}}} to "Master Award". So we'd get for example, "Artisan Master Award". The /language part is added by the {{GetLangSuffix}} call.
Category links can display something other than the category name, and in our case, that's what we want to do. We don't want to see "Category", nor do we want to see the "AY Honors/" part of the category name. That's a file organization detail, not something to display. Further, the category name is in English, which will not do if the invoking page is not English. So instead, we grab the Localized name of the master award, by fetching it from {{:Localization:English Name of Master Award{{GetLangSuffix}}}}.
After the switch statement we have this:
{{#if:{{{master1|}}}|...
The goal of that statement is so that we can add a <br> to mlist if the {{{master1}}} parameter was provided. Then :
{{#varexists:mlist|{{#vardefine:mlist|{{#var:mlist}}<br>}}}}
Which checks to see if we had assigned anything to mlist in the switch statement previously, and if we did, it redefines mlist ({{#vardefine:mlist...) by repeating the contents of mlist ({{#var:mlist}}) followed by the line break (<br>). It then repeats similar logic to append the category link to mlist:
{{#vardefine:mlist|{{#var:mlist}}[[:Category:AY Honors/{{{master1}}} Master Award{{GetLangSuffix}}{{!}}{{Localize|{{{master1}}} Master Award}}]]}}
As with the category-based logic in the switch statement, we are dealing with localization here too using very similar logic (using {{GetLangSuffix}} to link to the correct category, and the {{:Template:Translation...}} magic) just as before.
It then repeats that logic using {{{master2}}}.
Note that the {{!}} template is used to output a | within the [[:Category... link so that we can indicate the text displayed as the link. The use of the {{!}} template is necessary to prevent the {{#vardefine...}} function from interpreting it as its own separator.