Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Template:Trim

Template page
Revision as of 03:49, 2 September 2023 by Taylan (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This template returns its parameter without leading or trailing whitespace. It’s primarily for other templates to remove unwanted whitespace passed around an unnamed parameter (named parameters are automatically trimmed by MediaWiki).

Example:

{{trim | {{{1}}} }}

Additionally, this can be used for blocks of code in a page's source that would only produce empty lines, such as a series of {{#lvardef:}} declarations. By using this template, you can make such a block of code emit no output at all:

{{trim |
{{#lvardef: x | blah }}
{{#lvardef: y | blub }}
}}''The {{#lvar:x}} did {{#lvar:y}}.''

Output:

The blah did blub.

If you absolutely want line breaks after the }} at the end, without introducing blank lines in the output, then there's no way around using a div. This is sub-optimal because it will produce some output in the HTML that's ultimately sent to the browser, even if invisible:

<div>{{trim |
{{#lvardef: x | blah }}
{{#lvardef: y | blub }}
}}</div>

''The {{#lvar:x}} did {{#lvar:y}}.''

Output:

The blah did blub.