the monday night feature request: truncate truncate

by Christina - Miss Manners - 11:41PM, Jan 29, 2007

don’t ask – i just need this:

{{string | truncate:n}}
to really truncate down to n characters – not n – 3 + three dots.

ok, if you really want to know: i want to do stuff with “variant.sku”, namely reduce it from 9 characters to 6 (to create a related product family containing all products characterized by the first 6 characters of the full 9-character sku string)

what truncate does now is this: let’s take sku: ABC123XYZ

  • truncate 0 → ... (and same result for truncate 1 to 3)
  • truncate 4 → A…
  • truncate 5 → AB…
  • truncate 6 → ABC
  • truncate 7 → ABC1
  • truncate 8 → ABC12
  • truncate 9 → ABC123XYZ

none of which seems terribly useful.

if i’m trying to get just ABC123 - nothing more nothing less – that’s impossible.

so…if you can spare a few minutes of mad coding time :)?

edited despondently: oh never mind – that won’t be much use without a wildcard or a “contains”, will it? so maybe i’d be pushing my luck asking for 2 for the price of one on a monday night, what with all the goings-on on the fancy new dashboard. g’night all!

---

operation absurdist feature requests: terminated

(http://en.wikipedia.org/wiki/Absurdism)

Last edited 11:48PM, Jan 29, 2007

danW

Shopify Advisor

12:11AM, Jan 30, 2007

You could even bring the dots back with a different filter.

{{ ‘ABC123XYZ’ | truncate: 3 }} = ABC123
{{ ‘ABC123XYZ’ | truncate_with_dots: 3 | }} = ABC123

While we are on the subject of truncating, how about truncating the front of a string.

{{ ‘ABC123XYZ’ | truncate: -3 }} = 123XYZ

I have a had a few times where this would have come in handy.

tobi

Shopify

09:33PM, Jan 30, 2007

This should be possible. the second parameter to truncate is the string it uses to truncate with.

{{ string | truncate: 5, ’’ }} should do what you need.

---

Tobias Lütke
Shopify – Founder, CEO

Christina

Miss Manners

09:44PM, Jan 30, 2007

exactly! Thank you, Tobi!

---

operation absurdist feature requests: terminated

(http://en.wikipedia.org/wiki/Absurdism)

You must login to post a comment!

Don't have an account yet? Sign up for one.