< Template:SampRevision as of 20:32, 11 May 2024 by >Annh07
Purpose
This template is for explicitly indicating that the content inside it represents example output from a computer program or other machine source (automated attendant/interactive voice response call system, exit code of an application, standard output, LCD display, file name, etc.) It uses the [X]HTML element <samp>...</samp>
(sample output) which exists for this purpose, and applies some styling to it, namely a faint greying out of the text color to visually difference it from source code and input. It retains the default monospaced (non-proportional) font style of the <samp>
element. Because it uses <samp>...</samp>
instead of simply applying visual style effects, it is semantic markup that conveys meaning, and it can be further acted upon by the user agent (e.g. with custom local style sheets). This tag is the exact opposite of {{kbd}}
, which is for example input.
Usage
The template takes one mandatory parameter, the content to be marked up. If this content contains "=" (an equals sign), the parameter must be explicitly named |1=
, or the template will fail. (This is a limitation of the MediaWiki software, not the template.) It is always safer to use |1=
syntax. It may be used as a container for {{var}}
, {{varserif}}
or <var>...</var>
when the example output contains or consists entirely of a variable. It may also be used with (but not inside) {{code}}
, or with <code>...</code>
(it generally should not be used inside the latter, as output is not a part of source code, but something that results from it; however, this style can be used to illustrate computer display of mixed type, as illustrated below).
For cases where it is useful to display the color of the output, there is an optional parameter |color=
that takes an HTML color name or #nnnnnn
color code (in which case the #
is mandatory). For accessibility reasons, color should never be the only distinguishing factor, as foo and foo may be indistinguishable to color-blind readers.
There may also be cases where some other aspect of the output may need to be reproduced; the |style=
parameter accepts any complete CSS statement(s), terminating with a semicolon, e.g. |style=font-variant:small-caps; font-style:italic;
.
Examples:
{{samp|1=[A]bort, [R]etry, [F]ail?}}
: "The error message [A]bort, [R]etry, [F]ail? has been cited as notoriously user-unfriendly."
{{samp|%}}
with {{kbd|1=ssh {{var|hostname}}}}
: "At the % prompt, the user must enter ssh hostname."
{{samp|Error|color=red}}
, to indicate output color: On failure, the Error light activates.
{{samp|Error|color=red|style=font-variant:small-caps;}}
, for more customization: On failure, the Error light activates.
Some of these examples may look slightly different outside this documentation, because the default background color varies by page type (articles are stark white, template documentation pale green, most other pages very pale grey). In-article example:
{{samp|1=[A]bort, [R]etry, [F]ail?}}
: "The error message [A]bort, [R]etry, [F]ail? has been cited as notoriously user-unfriendly."
{{samp|%}}
with {{kbd|1=ssh {{var|hostname}}}}
: "At the % prompt, the user must enter ssh hostname."
{{samp|Error|color=red}}
, to indicate output color: On failure, the Error light activates.
{{samp|Error|color=red|style=font-variant:small-caps;}}
, for more customization: On failure, the Error light activates.
See also
Template:C |
---|
|
Template | Example output | Use |
---|
Template:Tlb | Important! | To indicate <strong> importance, seriousness, or urgency instead of just simple typographical boldfacing | Template:Tlb | "Never use ..." | Same as Template:Braces but in red | Template:Tlb | "Only use ..." | Same as Template:Braces but in green | Template:Tlb | "An emphatic phrase" | To indicate <em> stress emphasis (not just purely typographical italicization like for book titles or foreign terms) | Template:Tlb | strPrefix | To indicate text is a variable name. Use for any variable names except those including "I" (uppercase i) and/or "l" (lowercase L); for these, Template:Braces should be used to ensure a noticeable distinction | Template:Tlb | Template:Var serif | (see Template:Braces above) | Template:Tlb | {{DEFAULTSORT:Y, X}} | To display wikicode variables and magic words as they would appear in code | Template:Tlb | |year=2008 | To display template parameters with or without values | Template:Tlb | Template:Param | To display parameters as used in code (i.e. with triple braces), especially to indicate relationships between them. May be combined with Template:Braces above | Template:Tlb | Template:Tjp | To display template parameters with colors (as they would appear in the {{tj}} and {{tji}} templates) | Template:Tlb | Template:Pvalue | To display parameter values lightly bordered; replaces <code>...</code>, especially when value contains embedded or leading/trailing blanks; visualized here with middot (·) but can use ␠, ▯, or any character. | Template:Tlb etc. | {{Template|1|2|...|10}} | To display a template call (with or without parameters and values) as code | Template:Tlb | Page Template:Template journal inline/styles.css has no content.{{hatnoteLua error: expandTemplate: template "Template journal inline/arg" does not exist.}} | To showcase with colors in horizontal format the syntax of any template, while providing an easy way to display placeholder texts using colons as separators | Template:Tlb | "The <img>...</img> tags ..." | To render HTML elements ("tags") in prose | Template:Tlb/Template:Tlb | "Ensure the alt= parameter ..." | To indicate text is source code. To nest other templates within Template:Braces, use <code>...</code> . {{codett}} differs only in styling: someMethod becomes Template:Codett | Template:Tlb | "FORTH has keyword Template:PreCode." | Like Template:Tlb, but prevents line breaks inside the code. Only for very short code parts. | {{subst:codenowiki}} | {{small|small text example}} | To wrap example code in <code><nowiki>...</nowiki></code> | {{subst:kbdnowiki}} | {{large|large text example}} | To wrap example code in <kbd><nowiki>...</nowiki></kbd> | Template:Tlb | [this is a block template] | (Template:Thin space) Wrapper for <syntaxhighlight>...</syntaxhighlight> , but will wrap overflowing text | Template:Tlb | "Do not use <blink> ." | (Template:Thin space) To indicate deprecated source code in template documentation, articles on HTML specs, etc. The {{dc2}} variant uses strike-through (<blink> ) while {{dcr}} uses red (<Template:Dcr> ). | Template:Tlb | [this is a block template] | For larger blocks of source code and other pre-formatted text | Template:Tlb | [this is a block template] | To showcase with colors and multiple lines (vertical format) the syntax of any template, while providing an easy way to display placeholder texts using colons as separators | Template:Tlb | [this is a block template] | For block quotations (only – never for non-quotations) | Template:Tlb | [this is a block template] | For indented blocks of material; visually identical to {{quote}} but without quote markup | Template:Tlb | user input | To indicate user input | Template:Tlb | Ctrl+x | To indicate specific-keystroke input, including combinations | Template:Tlb | Template:Key top | Similar; includes more symbols, but does not directly support combinations | Template:Tlb | Don't save | To indicate a button in a user interface | Template:Tlb | example output | To indicate sample or example output |
|
|