CASE: use default in a variable

Let’s say we want to display the name of the street of the file. As you know, both name and number is saved into one field {{ company.street }}.
We can use the remove-tag however to strip any number that is saved into that object, by doing this:

{% assign company_city = company.street | remove:"1" | remove:"2" | remove:"3" | remove:"4" | remove:"5" | remove:"6" | remove:"7" | remove:"8" | remove:"9" | remove:"0" %}

Street = {{ company_city }} 

This will work in 95% of the cases, but if your street-address is “Gaston Crommenlaan 12 bus 3”, you’ll end up with this:

We cannot make code to have this functioning 100% (that’s an honest fact). We can however create an input-object that displays the value of our variable company_street where the user can overwrite the value in it (if it’s indeed mistaken and has to be corrected):

{% input custom.vkt_1.street | default:company_city %} 

which gives this, where the user can change the data, if needed:


The default-tag displays the value in our objects, but never actually fills the objects with that value! You can test this by using the object further in your template: it won’t show the default-value, because in reality it’s empty!
If you change the default-value however, by changing it or put in a new name, only then will the data been stored into the object. Because only then are you actually putting in data.
An input-tag will never put in the default-value into an object; that’s simply how it works. It has to be inputted for that, and a default is not really inputted (only being displayed).

If you want to go around this, and let the default-value display no matter if you’ve changed the data or not, you can assign it into a variable with the default-tag like this:

{% assign street = custom.vkt_1.street | default:company_city %}


{{ street }} 

No matter if you change the object or not, it’ll always display and have the correct data into its object!

1 Like