Bản mẫu này được sử dụng ở khoảng 164.000 trang. Để tránh gây lỗi trên quy mô lớn và tải máy chủ không cần thiết, tất cả thay đổi cần được thử nghiệm ở trang con /sandbox, /testcases của bản mẫu, hoặc ở không gian người dùng của bạn. Các thay đổi đã được thử nghiệm có thể thêm vào bản mẫu bằng một sửa đổi duy nhất. Xin hãy thảo luận các thay đổi tại trang thảo luận trước khi áp dụng sửa đổi. |
{{Str left|<string>|<count>}}
Gives the resultant <count> of characters creating a substring of characters from the start of the trimmed string (i.e. the substring returned will have length <count>, exclusive of leading whitespace characters, which are trimmed first before <count> is invoked).
If <count> is invalid, empty or zero, an empty string is returned. If undefined, it defaults to 1.
{{ Str left | Lorem ipsum dolor sit amet | 10 }}
→ Lorem ipsu{{Str left| Lorem ipsum dolor sit amet | 4 }}
→ Lore, (note leading spaces trimmed!){{ Str left | Lorem ipsum dolor sit amet | 1 }}
→ L{{ Str left | Lorem ipsum dolor sit amet | 0 }}
→{{ Str left | Lorem ipsum dolor sit amet | }}
→{{ Str left | Lorem ipsum dolor sit amet }}
→ L{{ Str left | Lorem ipsum dolor sit amet | 40 }}
→ Lorem ipsum dolor sit ametLorem ipsum do{{ Str left | àçé | 2 }}
→ àç
All the limitations of use for this template and shown below are caused by the current implementation of the {{padleft:}} parser function used in this template, which does not filter its third parameter containing the characters used for padding a string to the specified length (it currently counts incorrectly the characters to extract from the padding string, and incorrectly measures its effective length; in addition this parameter is limited to 500 bytes).
The following examples are demonstrating that this template is not safe with character entity references found in its string parameter :
{{ Str left | a c | 3 }}
→ a&n
{{ Str left | aBc | 3 }}
→ a&#
{{ Str left | a c | 3 }}
→ a c
{{ Str left | a c | 3 }}
→ a&#
The following example shows that the presence of some wiki markup that should be transparent and ignored, does not allow this template to work as expected (the nowiki section is replaced by a unique index string in the effective runtime value of the parameter; this unique (43-bytes long) string starts by a control character (which will be finally filtered out from the generated HTML page if it remains in the result of this template), followed by "UNIQ" and some unique sequence and terminated by "QINU" and a final control character; it is partially visible below, because the unique string is not complete after truncation, and then cannot be eliminated from the output in the first two lines):
{{ Str left | a<nowiki/>bc | 3 }}
→ abc
{{ Str left | a<nowiki/>bc | 43 }}
→ abcabcabcabcabcabcabcabcabcabcabcabcabcabca
{{ Str left | a<nowiki/>bc | 44 }}
→ abcabcabcabcabcabcabcabcabcabcabcabcabcabcab
{{ Str left | a<nowiki/>bc | 45 }}
→ abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcOn the opposite, the HTML comments, and the "noinclude", "includeonly" and "onlyinclude" wiki markup tags are safe, because they are preprocessed in template parameters, before including it and substituting parameters:
{{ Str left | a<noinclude/>bc | 3 }}
→ abc{{ Str left | a<!-- comment -->bc | 3 }}
→ abcNote also that the specified length will cause the input string to be padded by repeating it, if this length is larger than the input string length:
{{ Str left | Abc. | 10 }}
→ Abc.Abc.Ab