How to show binding only if it's not empty

I am trying to format an address using bindings from a database. I have two address fields but most of the 2nd address fields are empty. I want to only show the 2nd address field if it is not empty. I know how to do this in PHP and I know this is probably really easy in Wappler, but I haven’t been able to find the answer. My line of code is:

{{school}} — {{phone}}
{{address1}}
{{address2}}
{{city}}, {{state}}, {{zip}}

Any ideas?

HI,
put {{address2}} inside a span
Try this
<span dmx-show="address2">{{address2}}</span>

1 Like

Thank you! I knew it would be easy.

For each part of the address to be on a separate line, won’t you need to add <br> tags - and then wrap div tags around the span and put the dmx-show=" inside the div?

I’m probably missing something - or perhaps there’s a better solution. Eg in PHP I often use a function using preg_replace and a regular expression to strip out blank lines from blocks of text (like addresses). I wonder if it would be possible to use Wappler’s formatter to create similar functionality.

Well yes, you would need <br>.
I usually create a list and add the dmx-show inside the li tag

Thank you.
Regarding the <div> it can also work. After all, these approaches depend on how you are used to organizing your code.

1 Like

I like your suggestion of using li tags - I think that’s a better solution. Thanks.