Difference between revisions of "Template:Habitats"
Jump to navigation
Jump to search
(made "or" an option) |
(For your consideration. Significantly lighter, and only needs 1 new line per new biome (if more are ever added). Feel free to revert.) |
||
Line 2: | Line 2: | ||
Returns a nicely-formatted list of all the biomes an animal can appear in. | Returns a nicely-formatted list of all the biomes an animal can appear in. | ||
− | For example, if used on [[Timber wolf]], the result is: {{Habitats|Timber wolf}} | + | For example, if used on [[Timber wolf]], the result is: {{Habitats|Timber wolf}}. |
− | You can also make it produce "or" rather than "and" by doing<code><nowiki>{{Habitats|Timber wolf|or}}:</nowiki></code>{{Habitats|Timber wolf|or}} | + | You can also make it produce "or" rather than "and" by doing<code><nowiki>{{Habitats|Timber wolf|or}}:</nowiki></code>{{Habitats|Timber wolf|or}}. |
− | </noinclude><includeonly>{{#vardefine: | + | </noinclude><includeonly> |
− | {{#if:{{Q|{{{1|{{PAGENAME}}}}}|Lives In Temperate Forest}}|[[temperate forest]]s | + | {{#vardefine: habitatString | {{#if:{{Q|{{{1|{{PAGENAME}}}}}|Lives In Temperate Forest}}|[[temperate forest]]s, }}<!-- |
+ | -->{{#if:{{Q|{{{1|{{PAGENAME}}}}}|Lives In Temperate Swamp}}|[[temperate swamp]]s, }}<!-- | ||
+ | -->{{#if:{{Q|{{{1|{{PAGENAME}}}}}|Lives In Tropical Rainforest}}|[[tropical rainforest]]s, }}<!-- | ||
+ | -->{{#if:{{Q|{{{1|{{PAGENAME}}}}}|Lives In Tropical Swamp}}|[[tropical swamp]]s, }}<!-- | ||
+ | -->{{#if:{{Q|{{{1|{{PAGENAME}}}}}|Lives In Arid Shrubland}}|[[arid shrubland]]s, }}<!-- | ||
+ | -->{{#if:{{Q|{{{1|{{PAGENAME}}}}}|Lives In Desert}}|[[desert]]s, }}<!-- | ||
+ | -->{{#if:{{Q|{{{1|{{PAGENAME}}}}}|Lives In Extreme Desert}}|[[extreme desert]]s, }}<!-- | ||
+ | -->{{#if:{{Q|{{{1|{{PAGENAME}}}}}|Lives In Boreal Forest}}|[[boreal forest]]s, }}<!-- | ||
+ | -->{{#if:{{Q|{{{1|{{PAGENAME}}}}}|Lives In Cold Bog}}|[[cold bog]]s, }}<!-- | ||
+ | -->{{#if:{{Q|{{{1|{{PAGENAME}}}}}|Lives In Tundra}}|[[tundra]], }}<!-- | ||
+ | -->{{#if:{{Q|{{{1|{{PAGENAME}}}}}|Lives In Ice Sheet}}|[[ice sheet]]s, }}<!-- | ||
+ | -->{{#if:{{Q|{{{1|{{PAGENAME}}}}}|Lives In Sea Ice}}|[[sea ice]], }}}}<!-- | ||
+ | Extract the last term, if its the only term then print it, else replace the last term in the whole string with the last term with the and/or in front of it, then trim the extraneous comma and space off the final string | ||
+ | -->{{#ifeq: {{#vardefineecho: lastTerm | {{#explode:{{#var: habitatString}}|, |-2}} }},  | {{#var: habitatString}}|{{#var: lastTerm}}|{{#sub:{{#replace:{{#var: habitatString}}|{{#var: lastTerm}}| {{#if:{{{2|}}}|or|and}} {{#var: lastTerm}}}}||-6}} }}</includeonly> |
Revision as of 00:56, 5 October 2021
Returns a nicely-formatted list of all the biomes an animal can appear in.
For example, if used on Timber wolf, the result is: temperate forests, temperate swamps, boreal forests, cold bogs, and tundra.
You can also make it produce "or" rather than "and" by doing{{Habitats|Timber wolf|or}}:
temperate forests, temperate swamps, boreal forests, cold bogs, or tundra.