If not empty

John_Conway
Tourist
21 0 1

Hi – no doubt this is something simple, but… I'm editing addresses.liquid and in the display of the user's addresses I want each line to be surrounded by an if statement, so that the line is only outputted if the appropriate field has been completed in the first place. I have for example this:                

				{% if address.address2 != nil %}
					{{ address.address2 }}<br />
				{% endif %}

But I'm finding that the <br /> is outputted regardless of whether or not address 2 has been filled in, so if the if statement doesn't seem to be working?

 

0 Likes
APAD1
Shopify Partner
120 0 7

I don't think you need to actually put "nil" in there to check against nil, I think it would work just like this:

{% if address.address2 %}
	{{ address.address2 }}<br />
{% endif %}
0 Likes
John_Conway
Tourist
21 0 1

Thanks – alas doesn't seem to work either, still getting the same thing though: address.address2 outputted when there is one, but otherwise just the break?

0 Likes
APAD1
Shopify Partner
120 0 7

Are you sure the line break you're seeing is the one that's within the conditional statement? Maybe the statement is inside of a div that is causing the line break? If the address is being hidden then the <br> should be as well.

0 Likes
John_Conway
Tourist
21 0 1

Good idea but yes, sure – I tried changing the code to this and now I get                

				{% if address.address2 %}
					{{ address.address2 }}Test<br />
				{% endif %}

Test<br /> output even if there is no address.address2

0 Likes
John_Conway
Tourist
21 0 1

Figured it out – this did it!

{% if customer.name != '' %}
	{{ customer.name }}
{% endif %}

Thanks again.

APAD1
Shopify Partner
120 0 7

Glad you got it sorted, thanks for sharing the solution!

0 Likes
bnzwanzig
New Member
1 0 1
{% if image == blank %}
    {% continue %}    	
{% endif %}

 

this condition works for me

Niraj-Pathak
New Member
2 0 1
{% if address.address2 != blank %}
					{{ address.address2 }}Test<br />
				{% endif %}

Try this I hope this will work.