Template:Nw: Difference between revisions
m (Porplemontage moved page Template:Nowrap to Template:Nw) |
m (Text replacement - "({{|[Tt]em\|)[Nn]owrap" to "$1nw") |
||
Line 6: | Line 6: | ||
== Usage == | == Usage == | ||
<pre> | <pre> | ||
Lots of text {{ | Lots of text {{nw|10 kg (22 lb)}} more text. | ||
</pre> | </pre> | ||
Line 26: | Line 26: | ||
For text that includes an equal sign "=", precede the text with <code>1=</code>. For example: | For text that includes an equal sign "=", precede the text with <code>1=</code>. For example: | ||
:<code><nowiki>{{ | :<code><nowiki>{{nw|</nowiki>1=2 + 2 = 4}}</code> | ||
Which renders this: | Which renders this: | ||
:{{ | :{{nw|1=2 + 2 = 4}} | ||
For text that includes a vertical bar "|", escape the bar(s) with <code><nowiki>&#124;</nowiki></code> or <code><nowiki>{{!}}</nowiki></code>. For instance like this: | For text that includes a vertical bar "|", escape the bar(s) with <code><nowiki>&#124;</nowiki></code> or <code><nowiki>{{!}}</nowiki></code>. For instance like this: | ||
:<code><nowiki>{{ | :<code><nowiki>{{nw|</nowiki>&#124;2&#124; < 3}}</code> | ||
Or like this: | Or like this: | ||
:<code><nowiki>{{ | :<code><nowiki>{{nw|{{!}}2{{!}} < 3}}</nowiki></code> | ||
Which renders this: | Which renders this: | ||
:{{ | :{{nw||2| < 3}} | ||
== Technical details == | == Technical details == |
Revision as of 10:27, June 4, 2024
This template prevents word wraps (line breaks) in text and links that contain spaces.
Before you use this template you might want to read up on line-break handling.
Usage
Lots of text {{nw|10 kg (22 lb)}} more text.
It may render like this:
- Lots of text 10 kg (22 lb)
- more text.
Or like this:
- Lots of text
- 10 kg (22 lb) more text.
But it will not render like this:
- Lots of text 10 kg (22
- lb) more text.
Handling interpreted characters
Templates have problems to handle parameter data that contains equal signs "=
" or vertical bars "|
". But there are also workarounds:
For text that includes an equal sign "=", precede the text with 1=
. For example:
{{nw|1=2 + 2 = 4}}
Which renders this:
- 2 + 2 = 4
For text that includes a vertical bar "|", escape the bar(s) with |
or {{!}}
. For instance like this:
{{nw||2| < 3}}
Or like this:
{{nw|{{!}}2{{!}} < 3}}
Which renders this:
- |2| < 3
Technical details
The actual code that does the job is this HTML+CSS code:
<span style="white-space:nowrap">This text will not wrap</span>
Spaces at the beginning or end of your text will fall outside the no-wrap tag in the rendered text due to MediaWiki rendering mechanisms.