Skip to main content
Answer

Conditional != or !== statements in Liquid

  • July 1, 2024
  • 2 replies
  • 79 views

FaredoonCR
Apprentice

Hi there,

 

I’m trying to use a conditional statement that checks for 

  • navigator.useragent
  • sessionStorage.get(‘some item’)
  • localStorage.get(‘some item’)

E.g. {% if localStorage.get('some-item') != undefined  %}

<div>Some div</div>

{% else %}

<div>Some other div</div>

{% endif %}  

 

When I preview the page, this doesn’t seem to do what I intend. E.g. if there is no localStorage with that key, it still shows “Some div”

Best answer by mahendarsingh

Hi ​@FaredoonCR,

Firstly apologize for the delay. I understand that you want to get in touch with the developer community members, Our team is waiting for your comments so please feel free to post. the query on https://community.freshworks.dev/ where our dev community would be able to assist you with solution to your queries. 

Thank you !!

2 replies

mahendarsingh
Community Manager
Forum|alt.badge.img+9
  • Community Manager
  • Answer
  • August 9, 2025

Hi ​@FaredoonCR,

Firstly apologize for the delay. I understand that you want to get in touch with the developer community members, Our team is waiting for your comments so please feel free to post. the query on https://community.freshworks.dev/ where our dev community would be able to assist you with solution to your queries. 

Thank you !!


Daniel Söderlund
Top Contributor ⭐
Forum|alt.badge.img+14

Hi there,

 

I’m trying to use a conditional statement that checks for 

  • navigator.useragent
  • sessionStorage.get(‘some item’)
  • localStorage.get(‘some item’)

E.g. {% if localStorage.get('some-item') != undefined  %}

<div>Some div</div>

{% else %}

<div>Some other div</div>

{% endif %}  

 

When I preview the page, this doesn’t seem to do what I intend. E.g. if there is no localStorage with that key, it still shows “Some div”

{% if localStorage.get('some-item') %}
True, there are data 
{% else %}
false there are no data 
{% endif %}