Skip to main content
Solved

Separate two shipment tracking numbers that are in the same field


Forum|alt.badge.img

Hello!

I’m trying to separate shipment tracking numbers in my Shipping Confirmation transactional email. Both outbound and return tracking numbers appear under the same event property, on one row, and I want to display them separately.

 

The two values are separated by a space.

The event variable is {{ event.TrackingNumber|default:’’ }}. If I change it to {{ event.TrackingNumber|first }}, it only displays the first single digit/letter of the value. Same if I change to last, it only gives the last digit/letter.

How can I edit my event variable to display the full first or second value, on either side of the space?

Grateful for help!

 

Best regards,

Peter Sandblad

Best answer by retention

Hi ​@PeterSandblad, welcome to the community!

Try the “Split” Filter and specify the “space character” as your separator and then use the First/Last filter to select the first or last item in the resulting array.  In your case, you only have two items in the array which happens to line up nicely as the First and the Last.

From the documentation: Django filter glossary : Split

split

str | Optional[str] → List[str]

Splits a string into a list of substrings based on a given separator.

Example:

{{ "apple,orange,banana"|split:"," }}

 

So I think your code should look like this:

{{ event.TrackingNumber | split:” “ | first }}

{{ event.TrackingNumber | split:” “ | last }}

Give that a try and let us know if it worked!

View original
Did this topic or the replies in the thread help you find an answer to your question?

3 replies

retention
Partner - Platinum
Forum|alt.badge.img+62
  • 2025 Champion
  • 920 replies
  • Answer
  • January 15, 2025

Hi ​@PeterSandblad, welcome to the community!

Try the “Split” Filter and specify the “space character” as your separator and then use the First/Last filter to select the first or last item in the resulting array.  In your case, you only have two items in the array which happens to line up nicely as the First and the Last.

From the documentation: Django filter glossary : Split

split

str | Optional[str] → List[str]

Splits a string into a list of substrings based on a given separator.

Example:

{{ "apple,orange,banana"|split:"," }}

 

So I think your code should look like this:

{{ event.TrackingNumber | split:” “ | first }}

{{ event.TrackingNumber | split:” “ | last }}

Give that a try and let us know if it worked!


retention
Partner - Platinum
Forum|alt.badge.img+62
  • 2025 Champion
  • 920 replies
  • January 15, 2025

Oh, if it wasn’t obvious, just to add:  to only show the “First” you use this:

{{ event.TrackingNumber | split:” “ | first }}

 

If you want to show the “Last” somewhere else, you use this:

{{ event.TrackingNumber | split:” “ | last }}


Mich expert
Problem Solver IV
Forum|alt.badge.img+11
  • Problem Solver IV
  • 64 replies
  • January 15, 2025

To separate the shipment tracking numbers into two fields (outbound and return) when they're in the same field separated by a space, use the split filter. Here's how you can do it in simple terms:

  • To get the first tracking number (outbound):

     

    django

    Copy code

    {{ event.TrackingNumber | split:" " | first }}

  • To get the second tracking number (return):

     

    django

    Copy code

    {{ event.TrackingNumber | split:" " | last }}

This works because the split:" " filter breaks the single string into two parts based on the space, and first or last picks the respective part. Try it, and let us know

 

Best regard 

Micheal expert