https://sudoroom.org/mediawiki/index.php?title=Template:Str_%C3%A2%E2%80%B0%C2%A4_len/doc&feed=atom&action=historyTemplate:Str ≤ len/doc - Revision history2024-03-29T10:53:03ZRevision history for this page on the wikiMediaWiki 1.37.2https://sudoroom.org/mediawiki/index.php?title=Template:Str_%C3%A2%E2%80%B0%C2%A4_len/doc&diff=1313&oldid=prevMaximilianklein: 1 revision2012-12-12T07:47:06Z<p>1 revision</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<tr class="diff-title" lang="en">
<td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 00:47, 12 December 2012</td>
</tr><tr><td colspan="2" class="diff-notice" lang="en"><div class="mw-diff-empty">(No difference)</div>
</td></tr></table>Maximiliankleinhttps://sudoroom.org/mediawiki/index.php?title=Template:Str_%C3%A2%E2%80%B0%C2%A4_len/doc&diff=1312&oldid=prev122.134.190.114: +ja2012-01-28T10:12:45Z<p>+ja</p>
<p><b>New page</b></p><div>{{Documentation subpage}}<br />
{{high-risk| 350,000+ }}<br />
<!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE --><br />
<br />
This is the {{tl|str ≤ len}} meta-template.<br />
<br />
It helps other templates check if a string is "shorter or equally long" vs. "longer" than a given length.<br />
<br />
=== Usage ===<br />
<br />
This template takes 3 to 4 unnamed parameters.<br />
<br />
Here is how to check if the string "abcde" is 4 characters or less:<br />
<br />
<pre><br />
{{str ≤ len | abcde | 4<br />
| Equal or shorter.<br />
| Longer.<br />
}}<br />
</pre><br />
<br />
Which returns this:<br />
<br />
:{{str ≤ len | abcde | 4<br />
| Equal or shorter.<br />
| Longer.<br />
}}<br />
<br />
Templates have a problem to handle parameter data that contains equal signs "<code>=</code>". But that is easily solved by using numbered parameters. Here we check if the string "ab=cde" is 100 characters or less:<br />
<br />
<pre><br />
{{str ≤ len <br />
| 1 = ab=cde <br />
| 2 = 100<br />
| 3 = Equal "=" or shorter.<br />
| 4 = Longer, not "=".<br />
}}<br />
</pre><br />
<br />
Which returns this:<br />
<br />
:{{str ≤ len <br />
| 1 = ab=cde <br />
| 2 = 100<br />
| 3 = Equal "=" or shorter.<br />
| 4 = Longer, not "=".<br />
}}<br />
<br />
It probably is a good habit to always use the numbered parameters, since you might not know beforehand exactly how the data will look that your template will feed to this meta-template.<br />
<br />
=== Parameters ===<br />
<br />
Detailed parameter explanation:<br />
<br />
<pre><br />
{{str ≤ len <br />
| 1 = A string, 0-500 characters long.<br />
| 2 = 0 - 500<br />
| 3 = Data to return/render when "shorter than or equally long".<br />
| 4 = Data to return/render when "longer than".<br />
}}<br />
</pre><br />
<br />
Empty or undefined strings are considered to be of 0 length. Strings longer than 500 are not truncated to 500.<br />
<br />
Length values below 0 are considered to be 0. Length values above 500 are considered to be 500.<br />
<br />
Thus a string longer than 500 is always considered to be "longer", even if it is compared with the "correct" length value.<br />
<br />
=== Technical details ===<br />
<br />
The potential alternative templates names <nowiki>{{str <= len}} or (for the opposite) {{str > len}}</nowiki> do not work in MediaWiki.<br />
<br />
Even though this is a string handling template it uses efficient code. (While some of the other string handling templates are probably so heavy on the servers that we perhaps should not use them.)<br />
<br />
[[Help:Template|Templates]] have problems to handle parameter data that contains pipes "<code>|</code>", unless the pipe is inside another template <code><nowiki>{{name|param1}}</nowiki></code> or inside a piped link <code><nowiki>[[Help:Template|help]]</nowiki></code>. Thus templates can not handle [[Help:Table|wikitables]] as input unless you escape them by using the {{tn|!}} template. This makes it hard to use wikitables as parameters to templates. Instead the usual solution is to use "[[Help:HTML in wikitext|HTML wikimarkup]]" for the table code, which is more robust.<br />
<br />
=== See also ===<br />
<br />
{{string templates see also}}<br />
<br />
<includeonly><br />
<!-- CATEGORIES AND INTERWIKIS HERE, THANKS --><br />
[[Category:String manipulation templates|{{PAGENAME}}]]<br />
[[ja:Template:Str ≦ len]]<br />
[[id:Templat:Str ≤ len]]<br />
[[ko:틀:Str ≤ len]]<br />
[[sl:Predloga:Str ≤ len]]<br />
</includeonly></div>122.134.190.114