Template:GetCropCat
From Pestinfo-Wiki
The template is similar to the Template:GetRegion. It takes one parameter (the name of a crop page) and converts it into a new string which includes the appropriate higher classification. E.g. the crop "Alfalfa/lucerne (Medicago sativa)" will be converted to "3E,Alfalfa/lucerne (Medicago sativa)" where "3E" is the code for "Forage/fodder crops". The codes are needed for sorting a list of crops according to their higher classification. If no category is found, the code 9Z (= unassigned crops) is used.
See also the corresponding Template:ShowCropCat for converting a code back to the name of the higher category.
The template has the following structure:
1. Define the empty variable "Label". If the assigned crop is "Grasses/turf/rangeland" or "Mushrooms" set the variables "Label" and "CropCat", otherwise determine the first category for the crop and assign it to the variable "CropCat". {{#vardefine:Label|}} {{#switch:{{{1}}} | Category:Grasses/turf/rangeland ={{#vardefine:CropCat|Forage/fodder crops}} {{#vardefine:Label|Grasses/turf/rangeland - All}} | Category:Mushrooms = {{#vardefine:CropCat|Mushrooms}}{{#vardefine:Label|Mushrooms - All}} | {{#vardefine:CropCat|{{GetCategory|{{{1}}} }} }} }} 2. Determine the code and assign it to the variable "CropCode". {{#vardefine:CropCode| {{#switch: {{#var:CropCat}} | Cereals/maize = 1A | Grain legumes = 1B | Oil crops = 1C | Root crops = 1D | Vegetables = 2A | Fruits/grape = 2B | Nut crops = 3A | Mushrooms = 3B{{#vardefine:Label|Mushrooms - {{{1}}} }} | Spices/herbs/medical plants = 3C | Stimulant crops = 3D | Forage/fodder crops = 3E | Grasses/turf/rangeland = 3E{{#vardefine:Label|Grasses/turf/rangeland - {{{1}}} }} | Forest/park trees = 3F | Ornamentals = 3G | Stored food = 4A | Stored products (other than food) = 4B | Fibre crops = 4C | Industrial crops = 4D | Other crops = 4E | 9Z }} }} 3. Return the combination of the category code and the crop {{#var:CropCode}},{{#if:{{#var:Label}}|{{#var:Label}}|{{{1}}}}}