Company city name in templates

Is it possible to get only the city name without the postal code?
If I use company.city I get the city name as well as the postal code…

Hello @Peter_GVB,

Welcome to our Community!

I’ve added your post in Templates instead of General.

To remove the postal code from our variable {{ company.city }} there are several things you could do:

{{ company.city | slice:5, 30 }}

This will start in your variable (which is a string) at position 5, and go to as long as position 30. So if everything start with the postal code (4 positions long) and a space, this will do just fine.

However, if you really want to be sure to remove every digit from you string, you can use this as well :

{{ company.city | remove:"0" | remove:"1" | remove:"2" | remove:"3" | remove:"4" | remove:"5" | remove:"6" | remove:"7" | remove:"8" | remove:"9"  }}

In this case, it will always remove numbers between 0 and 9. But, if you have a postal code with some letters in it (f.i. ‘FR’), then this might not be the perfect solution.
In that case, we should maybe fix this on our end.

For now, there’s not really a request that we split them up. So, with some triggering in Liquid-code you can work your way around it.

Hope this helps you. If not, ask away.

If you consistently put a certain character (e.g. a comma ,) between the zip-code and the city name, you can split on that character as well:
company.city = "9000, Gent"

{% assign zip_city = company.city | split:“,” %}

{% assign zip = zip_city[0] %}
{% assign city = zip_city[1] | strip %}

The strip filter ensures no spaces are prepended to the city name.

2 Likes

Great tip @robin.bailleul ! Much appreciated :+1:

Thank you all for the very useful tips. :slight_smile: