Jump to content

Template:File: Difference between revisions

From NixOS Wiki
m Improve file name spacing
DoggoBit (talk | contribs)
m make params consistent
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
<noinclude>{{Template}}{{DISPLAYTITLE:Template:file}}
<includeonly><div><div style="
 
  background-color: var(--background-color-neutral-subtle);
== About ==
  line-height: 1.3;
Used to display contents of a file.
  font-family: monospace;
{{META Pipe Character}}
   padding: 0.5em 1em;
 
  border-top-left-radius: 0.3rem;
== Usage ==
  border-top-right-radius: 0.3rem;
 
  border: 1px solid var(--border-color-muted);
<nowiki>{{file|filename|language|contents}}</nowiki>
  border-bottom: 0;
 
  margin-bottom: -1em;
See documentation about <code>&lt;syntaxhighlight></code> for supported languages.
  display: flow-root;
 
"><span style="
   <nowiki>{{file|main.c|c|
  font-size: 120%;
#include <stdio.h>
  font-weight: 900;
 
  color: {{{iconColor|{{file/color|{{{lang|{{{language|{{{2}}}}}}}}}}}}}};
main( )
">{{unicon|{{{icon|{{file/icon|{{{lang|{{{language|{{{2}}}}}}}}}}}}}}}}</span>&nbsp;{{{name|{{{filename|{{{1}}}}}}}}}</div>{{code|lang={{{lang|{{{language|{{{2}}}}}}}}}|line={{{line|}}}|copy={{{copy|yes}}}|highlight={{{highlight|}}}|{{{contents|{{{3}}}}}}}}</div></includeonly><noinclude>{{Documentation}}</noinclude>
{
        printf("hello, world\n");
}
}}</nowiki>
 
== Example ==
{{file|main.c|c|
#include <stdio.h>
 
main( )
{
        printf("hello, world\n");
}
}}
 
</noinclude><includeonly><div
  style="
    width: 1.2em;
    height: 0;
    position: relative;
    top: 0.8em;
    left: 0.8em;
  "
>{{{icon|[[Image:Breeze-text-x-plain.png|link=]]}}}</div>{{#tag:pre|{{{filename|{{{1|{{META Error}}}}}}}}
|style=margin-bottom: 0; border-bottom:none; padding-bottom:1.75em; padding-left:2.7em; margin-top: 0;
}}{{#tag:syntaxhighlight|{{{contents|{{{3|{{META Error}}}}}}}}
|lang={{{lang|{{{2| }}}}}}
|style=margin-top: -1em;}}</includeonly>

Latest revision as of 17:16, 11 June 2025

Template Documentation [edit source| uses| help]

This template is used to display the content of a file, or otherwise a block of code with the context of which file it would belong to.

🐍︎ main.py
def main():
  pass

if __name__ == "__main__":
  main()

Usage

Simply include this template in your page, specifying the language, file name and content of the file. Note that you may have to surround the code in <nowiki> tags in order to display it correctly.

{{file|main.c|c|
<nowiki>
#include <stdio.h>

main( )
{
        printf("hello, world\n");
}
</nowiki>
}}

Template data

Display a block of code alongside the name of the file it would belong to

Template parameters[Edit template data]

ParameterDescriptionTypeStatus
File namename

Name of the file the code belongs to

Stringrequired
Programming languagelang

The programming language used in the code

Stringrequired
Content3

The code to be displayed

Stringrequired
11

no description

Unknowndeprecated
22

no description

Unknowndeprecated
filenamefilename

no description

Unknowndeprecated
filefile

no description

Unknowndeprecated
contentscontents

no description

Unknowndeprecated
languagelanguage

no description

Unknowndeprecated