Template:Flag icon/doc

Revision as of 10:30, 4 June 2024 by wikipedia>Colonies Chris
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Template:Flag icon displays a flag of the named parameter in "icon" size, currently 23×15 pixels maximally (defined in Template:Flag icon/core), plus a one-pixel border. The image also has a clickable link to the associated article. For an unlinked flag icon, use Template:Flag decoration instead.

Please consider the Manual of Style section on flags before using this template.

Usage

{{Flag icon|name|variant=|size=|noredlink=}}

|1=name
The first parameter is mandatory, and identifies the name of the country, region, city, etc. A full list of available values can be found in Category:Country data templates. For example, Template:Country data Peru is used when the name parameter is specified as Peru. Many flags are also available via shortened "aliases", such as standard three-letter country codes as specified by ISO 3166-1 alpha-3, IOC, or FIFA. The list of available "aliases" is found in Category:Country data redirects. Many of these country codes could be considered obscure, so it is recommended to use the full country name.
|variant=
The second parameter is optional, and identifies a flag variant to be used instead of the standard flag. This is most often used for historical flags but can also be used to specify naval flags, sport-use flags, etc. The list of available flag variants for each country is documented on the specific page for the country data template. For example, Template:Country data Peru includes a description of each of the available flag variations for Peru. This parameter can be a named parameter (e.g.. "variant=1815"), or a positional parameter, always after the country name.
|size=
This parameter is optional, and is used to specify the maximum width and/or height of the flag image. This parameter is specified using standard image syntax.

Template data

This is the TemplateData for this template used by TemplateWizard, VisualEditor and other tools. See a monthly parameter usage report for Template:Flag icon in articles based on its TemplateData.

TemplateData for Flag icon

<templatedata> { "description": "This template displays a wikilinked flag of the named parameter in 'icon' size, currently 23×15 pixels (defined in Template:flag icon/core) plus a one-pixel border.", "params": { "1": { "label": "Name", "description": "Name of the country, region, city, etc.; full name is recommended for countries", "type": "string", "required": true }, "variant": { "label": "Variant", "description": "Identifies a flag variant to be used instead of the standard flag, e.g. 1815", "type": "string", "required": false, "aliases": [ "2" ] }, "size": { "label": "Maximum dimension", "description": "The maximum width or height, specified via standard 'extended image syntax' (e.g. x30px)", "type": "string", "required": false }, "noredlink": { "label": "No redlink", "description": "If set to any value which evaluates as true (i.e. '1', 'true', 'yes', or 'y'), it displays nothing if the country data file doesn't exist. (The default is to display a redlink)", "type": "string", "required": false } } } </templatedata>

Examples

Wikicode Results Notes
{{flag icon|Peru}} Peru
{{flag icon|PER}} Peru Uses the ISO/IOC/FIFA country code
{{flag icon|Peru|1822}} Peru Specifies a historical flag
{{flag icon|Peru|variant=1822}} Peru
{{flag icon|PER|naval}} Peru Specifies the naval ensign
{{flag icon|PER|air force}} Peru Specifies the air force flag
{{flag icon|Peru|size=50px}} Peru Sets width to 50 pixels
{{flag icon|Xanadu}} Template:Country data Xanadu No flag for Xanadu, so displays redlink
{{flag icon|Xanadu|noredlink=yes}} No flag, so displays nothing

Implementation notes

This template uses the data templates listed under Category:Country data templates, which contain the data specifying what to display and the formatter Template:flag icon/core, which contains the logic of how to display the flag.

Inside each country data template, this template uses the following parameters:

  • flag alias — name of the image file to display
  • flag alias-xxxx — name of the image file of flag variant xxxx
  • alias — used to display the alt attribute of the image (defaults to "Flag of alias")

Tracking categories

Where {{flag icon|Foo}} is used, but the Template:Country data Foo does not exist, then a redlink is displayed, unless the |noredlink=yes parameter has been set.

Where the redlink is displayed, the page is added to a tracking category:

Related templates

For a full list of flag templates, see Category:Flag template system.

Alternatives to avoid Wikipedia's Post-expand include size limit

Pages with many flag icons may come close to or exceed Wikipedia's Post-expand include size limit. In these cases consider using modules or module-wrapper templates instead:

  • {{flagg}} is a simple wrapper for Module:Flagg: For basic use, {{flag icon|country}} can be replaced with {{flagg|cxxlo|country}}
  • {{#invoke:flag|icon}} is a wrapper for Module:Flagg that can further reduce sizes when invoked directly. For basic use, {{flag icon|country}} can be replaced with {{#invoke:flag|icon|country}}.

See also