Template:Synced switch
Synced switch is a method to have content change at the same time as a switch infobox, without generating the associated buttons.
Usage
In general, the synced switch will switch to a version whenever a button with the associated switch ID (usually the 1-based index) is pressed somewhere on the page. This will generally be the # of version#
parameters of Module:Infobox-based switches (and infoboxes with integrated switch infobox), or the # of text#
parameters of Template:Switch infobox. If the item the infobox tries to switch to doesn't exist in the synced switch, it will switch to the default version.
In order to see the synced switch examples below in action, a simple Template:Switch infobox is here for switching.
Versions
The most basic and most common usage is to specify multiple numbered version#
parameters. Version 1 of the synced swithc will be shown when version 1 of the switched infobox is selected, etc.
This usage requires a switch infobox to be on the page (either a Module:Infobox-based infobox with multiple versions, or a Template:Switch infobox), as the setup for switching that infobox completes the setup of the synced switch, by applying the button texts (or select option texts) used by the infobox to the div tags of the synced switch.
Example code:
{{Synced switch |version1=content shown for variant 1 |version2=content shown for variant 2 }}
Example output:
Default
The default
parameter allows you to specify default content to be shown for all other unspecified switch versions.
Example code:
{{Synced switch |version1=content shown for variant 1 |version2=content shown for variant 2 |default=default content shown for all other switches }}
Example output:
Switch IDs
By default, infoboxes and this synced switch use a 1-based index as the switch ID. When a switch occurs, all items (synced switch or other switch infoboxes) with the corresponding switch ID get switched to. This can cause conflicts when a page has multiple unrelated switch infoboxes. Multi-version infoboxes and switch infoboxes allow manually specifying the switch ID using the switch_id#
parameter. To synchronize the sync switch to an infobox with specified switch IDs, you can specify corresponding switch_id#
values in the synced switch as well.
This switch infobox uses standard IDs (1,2,3) so that you can test it with the example below.
This switch infobox uses alternate IDs so that you can test it with the example below.
Example code:
{{Synced switch |version1=content shown for variant 1 with ID "alt1" |switch_id1=alt1 |version2=content shown for variant 2 with ID "alt2" |switch_id2=alt2 |version3=content shown for variant 3 with ID "alt3" |switch_id3=alt3 |default=default content shown for all other switches (including all switches from the other switch infobox at the top) }}
Example output:
No default switching
Optionally nodefault=y
(or =true
, etc) can be specified to tell the sync switch not to switch to a "default" state when an unspecified switch click occurs. Without this option, it defaults to nodefault=n
, which will switch the sync switch to the "default" state, even if no default content is specified via default
, which results in blank content.
The nodefault=y
option is particularly useful when there multiple switching infoboxes on the page, and one or more of them are using manually specified switch IDs. This option allows you to sync switching to one particular switch infobox and remain unchanged by clicks on another switch infobox.
This switch infobox uses standard IDs (1,2,3) so that you can test it with the example below.
This switch infobox uses alternate IDs so that you can test it with the example below.
Example code:
{{Synced switch |nodefault=y |version1=content shown for variant 1 with ID "alt1" |switch_id1=alt1 |version2=content shown for variant 2 with ID "alt2" |switch_id2=alt2 |version3=content shown for variant 3 with ID "alt3" |switch_id3=alt3 }}
Example output:
Buttons
Optionally buttons=true
can be specified to add buttons to the synced switch (has a similar visual to tabber tabs). Button text will match those on the infobox.
Example code:
{{Synced switch |version1=content shown for variant 1 |version2=content shown for variant 2 |default=default content shown for all other switches |buttons=true }}
Example not shown, see the "Text for buttons" section below.
Text for buttons
If the page:
- Has multiple Module:Infobox-based switches with differing button configurations
- Has no Module:Infobox-based switches - only having Template:Switch infobox-based switches (This is the case for this documentation page.)
- You wish to override the automatically applied button texts (version names) in order to match a different set of buttons or add multiple versions to one tab. Multiple versions should be separated by a broken bar/pipe (¦)
- You wish to override the displayed button text.
Then you will need to define the button texts and button displays manually by using corresponding text#
and button#
parameters. The text#
defines which switch infobox button text that the synced switch corresponds to. The button#
defines what text will be displayed on the synced switch button tab.
Default does not need button text, but the default button's tab text can be specified with defbutton
.
Example code:
{{Synced switch |buttons=true |text1=Item 1 |text2=Item 2¦other button text2 |version1=content shown for variant 1 |version2=content shown for variant 2 |button1=Displayed button text 1 |button2=Displayed button text 2 |default=content shown for all other variants |defbutton=Displayed default button text }}