Template:Code

Select
local function foo(argument)
	print(argument)
end
foo("Hello, world!")
[purge]Template-info.png Template documentation
This template allows you to have syntax highlighting and a tab width of 4 (can be edited by providing a different size argument) to present code. The default language is Lua.

Usage[edit]

{{code|[=]code[|lang=language][|tabwidth=width][|line numbers=true]}}

Note: text between brackets ([ and ]) is optional, text in bold represents a certain value (something you must replace) and the rest represents things that must be present as-is.

Parameters[edit]

[empty or 1]
The code itself.
lang
The language of the code. Must be one of the supported languages.
tabwidth
The width of the tabs. This should not be changed unless necessary, for consistency reasons.
line numbers
linenumbers
Whether line numbers should be shown.
copy button
Whether a button to copy the code should be displayed.

Notes[edit]

  • Only change the tab size if you absolutely need to. If changing the tab size is not absolutely necessary, please keep it to the default tab size, so this wiki can remain consistent.

Examples[edit]

Example[edit]

Code[edit]

{{code|lang=javascript
|alert("Hello World!");
}}

Result[edit]

alert("Hello World!");

Example[edit]

Code[edit]

{{code|=
for i = 1, 5 do
	print("Hello World!")
end
|copy button=true
|line numbers=true}}

Result[edit]

Select
  1. for i = 1, 5 do
  2. 	print("Hello World!")
  3. end

Example[edit]

Code[edit]

;DT item
:DD item, explaining some code
:{{code|=
for i = 1, 5 do
	print("Uh oh, there's a bug!")
end
}}

Result[edit]

DT item
DD item, explaining some code
for i = 1, 5 do
print("Uh oh, there's a bug!") end
</section>