Hello everyone!
If you print text in the text element (or in the header element) in the form of dynamic tags: {dynamic_tag_1} {dynamic_tag_2} {dynamic_tag_3}, then everything works. This is correct and convenient.
But with this method of text output, there is often a problem with spaces. If one of the tags is empty, then it is not displayed at all, and this is correct. But at the same time, extra spaces appear in the final text: at the beginning, in the middle or at the end.
I think the option to trim extra spaces is needed for text elements. Something like the trim function.
Has anyone encountered anything like this? Maybe there are already solutions? 
Hey Evgeniy,
the trim
function only “strips whitespace (or other characters) from the beginning and end of a string” (see documentation). So this won’t help here. And as there are so many different situations and use cases I guess you’re better off using a custom function. Bricks probably won’t be able to automatically figure out in which cases users want whitespace to be stripped.
Best,
André
The task is not very difficult - remove spaces at the beginning and at the end of the line, if there are any. Also, remove multiple spaces in the middle and leave only one space instead.
This task is solved through regular expressions. But how do I apply regular expressions to a text element? 
Hey Evgeniy,
what I was trying to say is that you might want whitespace to be stripped in your specific case. But there might be scenarios where whitespace has to be preserved. So Bricks shouldn’t make that decision automatically.
Best,
André
I agree that this does not need to be done automatically. Here you need an option that works in the on/off mode. If necessary, it is enabled and the spaces are deleted.
In general, it turns out that you need to work with regular expressions. Problems may arise not only with spaces, but also with other characters. You will not be able to do this manually. An automatic or semi-automatic tool is needed.
I agree with @aslotta that it isn’t something worth putting inside a builder functionality. As you have said, there can be many use cases, so IMO it’s better to write a custom function that suits your needs and just use it with echo
which already is a tremendously useful feature of this builder. Most software has this problem with using dynamic content and having single/multiple spaces around it depending on the situation. It seems easy but is quite hard to implement a robust solution and that’s precisely why no one bothers with it.
1 Like