I have two string variables that I want to display on a Django template. If variable a is empty, do not display it. Similar with b. But if a and b are both non-empty, then concatenate the two strings with a ' & '.
Here's the logic in Python.
res = ''
if a != '':
res = a
if b != '':
if res == '':
res = b
else:
res = res + ' & ' + b
print(res)
How would I write this logic into a Django template?
res = ' & '.join(filter(None, [a, b]))