2

My code:

CASE 
WHEN length("Straße/Nr.")>0 THEN ( ( 'Name: '+ "Name" ) +'<br>'+  ( 'Straße: ' + "Straße/Nr." ) +'<br>'+ ('Religion: ' + "Religion" ) +'<br>'+ (  'URL: '+  "URL" ) ) 
WHEN length("Name")>0 THEN( ( 'Name: '+ "Name" )  +'<br>'+ ('Religion: ' + "Religion" ) +'<br>'+ (  'URL: '+  "URL" ) ) 
WHEN length("Religion")>0 THEN(  ('Religion: ' + "Religion" ) +'<br>'+ (  'URL: '+  "URL" ) ) 
WHEN length("URL")>0 THEN( (  'URL: '+  "URL" )) 
END

Result:

enter image description here

All is OK, but one problem: How can I hide "URL: " if there are no content?

I have different results in my popups of qgis2web: Sometimes I have no value for URL or sometimes no value for Religion. All ok. Only the "URL:" is my problem.

Any ideas?

1 Answer 1

1

Seems to me a bug in your expression. Try with the following:

IF( length( "Name") > 0, ( 'Name: ' + "Name") + '<br>', '') +
IF( length( "Straße/Nr.") > 0, ( 'Straße: ' + "Straße/Nr.") + '<br>', '') +
IF( length( "Religion") > 0, ( 'Religion: ' + "Religion") + '<br>', '') +
IF( length( "URL") > 0, ( 'URL: ' + "URL" ) + '<br>', '')
4
  • Perfect! Thank you very much.
    – Jürgen
    Nov 16, 2019 at 8:58
  • Follow question: I have tried to insert blank characters after the word "name". With this command: IF( length( "Name") > 0, ( 'Name: '+ ' ' + "Name") + '<br>', '') +. In the table it looks like good, but in the popup (qgis2web/leaflet) no reaction, no more additional blank characters. Any idea? edit: upps, here the comment line shows the code not correct my blank characters - same problem here.....hmm. blank characters are there: 'Name: '+ ' HERE' + "Name"....
    – Jürgen
    Nov 16, 2019 at 9:03
  • 1
    You are welcome! It is a property of HTML, compresses all spaces between words in just one space. IF( length("Name")>0, ( 'Name: '+ '&nbsp;' +"Name" ) would work. Nov 16, 2019 at 11:08
  • Fantastic!! This I need.
    – Jürgen
    Nov 16, 2019 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.