Template:Code/doc
{{#switch:<translate></translate> | = {{#if:{{#ifexpr: ( {{#ifeq:doc|doc|1|0}} or ( {{#ifeq:{{#titleparts:template:code/doc|-1|-2}}|doc|1|0}} and {{#if:{{#translation:}}|1|0}} ) )|1|}}
|
{{#ifeq:show |show
| Template:Mbox }}{{#if: | | {{#ifexist:Template:Code | [[Category:{{#switch:Template | Template | Project = Template | Module = Module | User = User | #default = MediaWiki }} documentation pages{{#translation:}}]] | [[Category:Documentation subpages without corresponding pages{{#translation:}}]] }} }} | }}
| #default=
{{#invoke:Template translation|renderTranslatedTemplate|template=Template:Documentation subpage|noshift=1|uselang=⧼lang⧽}}
}}
Usage
This is a semantic markup wrapper template for the HTML element {{#if:|
|
}}{{#switch:pair
|c|close =
|s|single
|o|open
|p|pair = <code{{#if:| {{{params}}}}}
}}{{#switch:pair
|c|close =
|s|single = />
|o|open = >
|p|pair = >...
}}{{#switch:pair
|s|single
|o|open =
|c|close
|p|pair = </code>
}}{{#if:|
|
}}. It can be used without a parameter to wrap code in a formatted block, with syntax highlighting, or with {{safesubst:#if:|<templatestyles src="Template:Mono/styles.css"/>}}{{safesubst:#if:{{safesubst:#switch: 1
|no |n |false |0 = | = |¬ = |yes |y |true |1 = yes |#default = yes
}}|<templatestyles src="Template:Nowrap/styles.css"/>}}<{{safesubst:#if:|span class="monospaced {{safesubst:#if:{{safesubst:#switch: 1
|no |n |false |0 = | = |¬ = |yes |y |true |1 = yes |#default = yes
}}|nowrap}}"|code {{safesubst:#if:{{safesubst:#switch: 1
|no |n |false |0 = | = |¬ = |yes |y |true |1 = yes |#default = yes
}}|class="nowrap"}}}}>|{{safesubst:#if:inline|inline=}}</{{safesubst:#if:|span|code}}> for a leaner presentation.
Example:
<templatestyles src="Template:Mono/styles.css"/>{{#if:{{safesubst:#switch:
|no
|n
|false
|0 =
| =
|¬ =
|yes
|y
|true
|1 = yes
|#default = yes
}}|<templatestyles src="Template:Nowrap/styles.css"/>}}{{[[{{#if:|{{{SISTER}}}Template|Template}}:code|code]]{{#if:langTemplate:=css||langTemplate:=css}}{{#if:font-family: 'Times New Roman', serif;||font-family: 'Times New Roman', serif;}}{{#if:||{{{4}}}}}{{#if:||{{{5}}}}}{{#if:||{{{6}}}}}{{#if:||{{{7}}}}}{{#if:||...}}}}
produces:
- {{#if:|
|{{#if:|{{{header}}}}}font-family: 'Times New Roman', serif;
}}font-family: 'Times New Roman', serif;
Inline:
<templatestyles src="Template:Mono/styles.css"/>{{#if:{{safesubst:#switch:
|no
|n
|false
|0 =
| =
|¬ =
|yes
|y
|true
|1 = yes
|#default = yes
}}|<templatestyles src="Template:Nowrap/styles.css"/>}}{{[[{{#if:|{{{SISTER}}}Template|Template}}:code|code]]{{#if:inlineTemplate:=y||inlineTemplate:=y}}{{#if:langTemplate:=css||langTemplate:=css}}{{#if:font-family: 'Times New Roman', serif;||font-family: 'Times New Roman', serif;}}{{#if:||{{{5}}}}}{{#if:||{{{6}}}}}{{#if:||{{{7}}}}}{{#if:||...}}}}
produces:
- {{#if:y|
|{{#if:|{{{header}}}}}font-family: 'Times New Roman', serif;
}}font-family: 'Times New Roman', serif;
and is equivalent to:
<syntaxhighlight inline lang="css">font-family: 'Times New Roman', serif;</syntaxhighlight>
TemplateData
{{#switch:<translate></translate> |=
|no |n |false |0 = | = |¬ = |yes |y |true |1 = yes |#default = yes
}}|{{#ifexpr:{{#if:|{{#ifeq:Template:Code/doc|Template:Transclude|0|1}}|not{{#ifexpr: ( {{#ifeq:doc|doc|1|0}} or ( {{#ifeq:{{#titleparts:template:code/doc|-1|-2}}|doc|1|0}} and {{#if:{{#translation:}}|1|0}} ) )|1|0}}}}|Template:Navbar}}}} {{#if:||<translate> This is the [[<tvar name=1>Special:MyLanguage/Help:TemplateData</tvar>|TemplateData]] documentation for this template used by [[<tvar name=2>Special:MyLanguage/VisualEditor</tvar>|VisualEditor]] and other tools.</translate>}}
Code
{{#ifeq:doc|sandbox||{{#if:{{#ifexpr: (
{{#ifeq:doc|doc|1|0}} or ( {{#ifeq:{{#titleparts:template:code/doc|-1|-2}}|doc|1|0}} and {{#if:{{#translation:}}|1|0}} ) )|1|}}|[[Category:TemplateData documentation{{#translation:}}]]|[[Category:Templates using TemplateData{{#translation:}}]]}}}} | #default=
{{#invoke:Template translation|renderTranslatedTemplate|template=Template:TemplateData header|noshift=1|uselang={{#if:{{#ifeq:{{#invoke:Template translation|getLanguageSubpage|}}|en
|{{#ifeq:{{#titleparts:Code/doc||-1}}|en
|{{#invoke:Template translation|getLanguageSubpage|}} }}
|{{#invoke:Template translation|getLanguageSubpage|}} }}|{{#ifeq:{{#invoke:Template translation|getLanguageSubpage|}}|en |{{#ifeq:{{#titleparts:Code/doc||-1}}|en
|{{#invoke:Template translation|getLanguageSubpage|}} }}
|{{#invoke:Template translation|getLanguageSubpage|}} }}|⧼lang⧽}}}} }}
A block or inline source code string.
Parameter | Description | Type | Status | |
---|---|---|---|---|
Language | lang 2 | The programming language of the source code. List of valid values is at: Extension:SyntaxHighlight#Supported_languages
| String | suggested |
Inline? | inline | Whether to use inline formatting
| String | optional |
Class | class | Applies only if `inline=true` | String | optional |
ID | id | Applies only if `inline=true` | String | optional |
CSS Style | style | Applies only if `inline=true` | String | optional |
Header | header | Applies only if `inline` is not set | Line | optional |
Code | 1 code | The code to display. | String | required |
See also
- {{inline-code}}
- {{MW file}}
- {{git}}
- {{Codesample}}
- {{Terminal}}