Template:Trim: Difference between revisions
No edit summary |
HiddenDragon (talk | contribs) (Add documentation/template demo templates) |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
{{#if: {{{1|}}} | {{{1|}}} }}<noinclude> | <includeonly>{{#if: {{{1|}}} | {{{1|}}} }}</includeonly><noinclude>{{Documentation|content= | ||
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). | ||
Example: | Example: | ||
{{Template demo | |||
| style = table | |||
| <nowiki>{{trim | {{{1}}} }}</nowiki> | |||
}} | |||
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>{{#lvardef:}}</nowiki></code> declarations. By using this template, you can make such a block of code emit no output at all: | |||
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>{{# | |||
{{Template demo | |||
| style = table | |||
| <nowiki> | |||
{{trim | | {{trim | | ||
{{# | {{#lvardef: x | blah }} | ||
{{# | {{#lvardef: y | blub }} | ||
}}''The {{# | }}''The {{#lvar:x}} did {{#lvar:y}}.'' | ||
</nowiki> | |||
}} | |||
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: | 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: | ||
< | {{Template demo | ||
| style = table | |||
| <nowiki> | |||
<div>{{trim | | <div>{{trim | | ||
{{# | {{#lvardef: x | blah }} | ||
{{# | {{#lvardef: y | blub }} | ||
}}</div> | }}</div> | ||
''The {{# | ''The {{#lvar:x}} did {{#lvar:y}}.'' | ||
</ | </nowiki> | ||
}} | |||
}} | |||
}} | |||
[[Category:Templates]] | |||
</noinclude> | </noinclude> |
Latest revision as of 22:50, 19 January 2025
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:
Markup | Renders as |
---|---|
{{trim | {{{1}}} }} | {{{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:
Markup | Renders as |
---|---|
{{trim | {{#lvardef: x | blah }} {{#lvardef: y | blub }} }}''The {{#lvar:x}} did {{#lvar:y}}.'' |
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:
Markup | Renders as |
---|---|
<div>{{trim | {{#lvardef: x | blah }} {{#lvardef: y | blub }} }}</div> ''The {{#lvar:x}} did {{#lvar:y}}.'' |
The blah did blub. |