Template:Trim: Difference between revisions
(Created page with "{{#if:{{{1|}}}|{{{1|}}}}}<noinclude> 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: <pre>{{trim | {{{1}}} }}</pre> </noinclude>") |
No edit summary |
||
Line 1: | Line 1: | ||
{{#if:{{{1|}}}|{{{1|}}}}}<noinclude> | {{#if: {{{1|}}} | {{{1|}}} }}<noinclude> | ||
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). | 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). | ||
Line 5: | Line 5: | ||
<pre>{{trim | {{{1}}} }}</pre> | <pre>{{trim | {{{1}}} }}</pre> | ||
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 <code><nowiki>{{#vardefine:}}</nowiki></code> declarations. By using this template, you can make such a block of code emit no output at all: | |||
<pre> | |||
{{trim | | |||
{{#vardefine: x | blah }} | |||
{{#vardefine: y | blub }} | |||
}}''The {{#var:x}} did {{#var:y}}.'' | |||
</pre> | |||
Output: | |||
{{trim | | |||
{{#vardefine: x | blah }} | |||
{{#vardefine: y | blub }} | |||
}}''The {{#var:x}} did {{#var:y}}.'' | |||
If you absolutely want line breaks after the <code><nowiki>}}</nowiki></code> 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: | |||
<pre> | |||
<div>{{trim | | |||
{{#vardefine: x | blah }} | |||
{{#vardefine: y | blub }} | |||
}}</div> | |||
''The {{#var:x}} did {{#var:y}}.'' | |||
</pre> | |||
Output: | |||
<div>{{trim | | |||
{{#vardefine: x | blah }} | |||
{{#vardefine: y | blub }} | |||
}}</div> | |||
''The {{#var:x}} did {{#var:y}}.'' | |||
</noinclude> | </noinclude> |
Revision as of 22:42, 2 August 2023
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 {{#vardefine:}}
declarations. By using this template, you can make such a block of code emit no output at all:
{{trim | {{#vardefine: x | blah }} {{#vardefine: y | blub }} }}''The {{#var:x}} did {{#var: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 | {{#vardefine: x | blah }} {{#vardefine: y | blub }} }}</div> ''The {{#var:x}} did {{#var:y}}.''
Output:
The blah did blub.