diff --git a/filters/truncate.md b/filters/truncate.md index e2b4182..f3ebcbe 100644 --- a/filters/truncate.md +++ b/filters/truncate.md @@ -15,3 +15,37 @@ title: truncate ```text {{ "Ground control to Major Tom." | truncate: 20 }} ``` + +### Custom ellipsis + +`truncate` takes an optional second parameter that specifies the sequence of characters to be appended to the truncated string. By default this is an ellipsis (...), but you can specify a different sequence. + +The length of the second parameter counts against the number of characters specified by the first parameter. For example, if you want to truncate a string to exactly 10 characters, and use a 3-character ellipsis, use **13** for the first parameter of `truncate`, since the ellipsis counts as 3 characters. + +
Input
+{% raw %} +``` liquid +{{ "Ground control to Major Tom." | truncate: 25, ", and so on" }} +``` +{% endraw %} + +Output
+``` text +{{ "Ground control to Major Tom." | truncate: 25, ", and so on" }} +``` + +### No ellipsis + +You can truncate to the exact number of characters specified by the first parameter and show no trailing characters by passing a blank string as the second parameter: + +Input
+{% raw %} +``` liquid +{{ "Ground control to Major Tom." | truncate: 20, "" }} +``` +{% endraw %} + +Output
+``` text +{{ "Ground control to Major Tom." | truncate: 20, "" }} +``` diff --git a/filters/truncatewords.md b/filters/truncatewords.md index 6ac5ad0..b2480e2 100644 --- a/filters/truncatewords.md +++ b/filters/truncatewords.md @@ -15,3 +15,35 @@ Shortens a string down to the number of words passed as the argument. If the spe ```text {{ "Ground control to Major Tom." | truncatewords: 3 }} ``` + +### Custom ellipsis + +`truncatewords` takes an optional second parameter that specifies the sequence of characters to be appended to the truncated string. By default this is an ellipsis (...), but you can specify a different sequence. + +Input
+{% raw %} +``` liquid +{{ "Ground control to Major Tom." | truncatewords: 3, "--" }} +``` +{% endraw %} + +Output
+``` text +{{ "Ground control to Major Tom." | truncatewords: 3, "--" }} +``` + +### No ellipsis + +You can avoid showing trailing characters by passing a blank string as the second parameter: + +Input
+{% raw %} +``` liquid +{{ "Ground control to Major Tom." | truncatewords: 3, "" }} +``` +{% endraw %} + +Output
+``` text +{{ "Ground control to Major Tom." | truncatewords: 3, "" }} +```