Jump to content
MediaWiki

Template:Debug

From mediawiki.org
Template documentation

This is a debug template that echoes the arguments it was called with. You can easily spot errors in your code by temporarily replacing the name of a called template with Debug. The template is also useful while developing new templates that use subtemplates.

Ideally there should not be pages that permanently transclude this template.

Usage

[edit ]
  • {{Debug|hello|world|one{{!}}two{{!}}three{{!}}four|A {{=}} B|C = D|foo=bar}}
    ↳ {{Debug|1=hello|2=world|3=one{{!}}two{{!}}three{{!}}four|4=A = B|5=C = D|foo=bar}}

As a debug tool

[edit ]

If a template has, let's say, a problematic call to a {{FooBar}} template that generates errors, one must temporarily replace

{{FooBar
	| one = {{SOME COMPLICATE CODE HERE}
	| two = {{SOME COMPLICATE CODE HERE}
	| three = {{SOME COMPLICATE CODE HERE}
	| etc = etc
}}

with

{{Debug
	| one = {{SOME COMPLICATE CODE HERE}
	| two = {{SOME COMPLICATE CODE HERE}
	| three = {{SOME COMPLICATE CODE HERE}
	| etc = etc
}}

Once the errors are solved, the {{Debug}} template can be removed.

A naif workaround that does not require this template is that of temporarily replacing curly brackets with round brackets:

((FooBar
	| one = {{SOME COMPLICATE CODE HERE}
	| two = {{SOME COMPLICATE CODE HERE}
	| three = {{SOME COMPLICATE CODE HERE}
	| etc = etc
))

This however is less powerfull, because {{Debug}} takes care of escaping HTML entities and doing other quirks. The naif workaround will also not work when nested inside other templates or parser functions.

If the template in question is a substitution template and the call to the other template is of the type {{safesubst:<noinclude />FooBar}}, the following multi-level substitution must be used instead:

{{safesubst:<noinclude />Debug
	| one = {{SOME COMPLICATE CODE HERE}
	| two = {{SOME COMPLICATE CODE HERE}
	| three = {{SOME COMPLICATE CODE HERE}
	| etc = etc
}}

As a developer tool

[edit ]

This template is also useful when you start a new template that uses subtemplates: you must begin from somewhere, and so normally you begin from the parent template; there, instead of transcluding {{/foobar|...}} (which does not exist yet), you transclude {{Debug|...}}, which gives you feedback on what you are doing.

See also

[edit ]
The above documentation is transcluded from Template:Debug/doc. (edit | history)
Editors can experiment in this template’s sandbox (create | mirror) and testcases (create) pages.
Please add categories to the /doc subpage. Subpages of this template.

AltStyle によって変換されたページ (->オリジナル) /