Power Pages conditions handling

By | May 7, 2025

I’ve been doing some things wrong with Liquid, I just did not know it, as usual…

Take a look at the screenshot below, make not of those bold red “FALSE”-s, and notice how there are always… ALWAYS… braces surrounding the actual condition at least somewhere in the if statement in such cases:

I’ll have the code below just in case you wanted to try it for yourself. Here is how I interpret the results:

  • When using a number for comparison directly in the “if” statement, you should probably code it as a “string”. Otherwise, once there are braces around the condition, that condition will evaluate to false out of a sudden
  • The above is not true when comparing two variables, even if both a numbers. You don’t need to bother about string conversions

That’s a bit too subtle to my liking – I’ve been chasing this weird issue for the last few months, but, usually, would just shrug it off and change my if statements till they worked.

Anyways, here is the Liquid code for the test above:

<hr>
{% assign tagValue = request.params["tagId"] %}
<b>Tag Value: __ {{tagValue}} __</b><br/><br/>

if tagValue == 8: {% if tagValue == 8 %} TRUE {% else %} <font style="font-weight:bold;color:red">FALSE</font> {% endif %}<br/>
if (tagValue == 8): {% if (tagValue == 8) %} TRUE {% else %} <font style="font-weight:bold;color:red">FALSE</font> {% endif %}<br/>
if tagValue == "8": {% if tagValue == "8"  %} TRUE {% else %} <font style="font-weight:bold;color:red">FALSE</font> {% endif %}<br/>
if (tagValue == "8"): {% if (tagValue == "8") %} TRUE {% else %} <font style="font-weight:bold;color:red">FALSE</font> {% endif %}<br/>

<hr>
{% assign internalIntValue = 8 %}
<b>Internal Int Value: __ {{internalIntValue}} __</b><br/><br/>

if internalIntValue == 8: {% if internalIntValue == 8 %} TRUE {% else %} <font style="font-weight:bold;color:red">FALSE</font> {% endif %}<br/>
if (internalIntValue == 8): {% if (internalIntValue == 8) %} TRUE {% else %} <font style="font-weight:bold;color:red">FALSE</font> {% endif %}<br/>
if internalIntValue == "8": {% if internalIntValue == "8"  %} TRUE {% else %} <font style="font-weight:bold;color:red">FALSE</font> {% endif %}<br/>
if (internalIntValue == "8"): {% if (internalIntValue == "8") %} TRUE {% else %} <font style="font-weight:bold;color:red">FALSE</font> {% endif %}<br/>

<hr>
{% assign internalStringValue = "8" %}
<b>Internal String Value: __ {{internalStringValue}} __</b><br/><br/>

if internalStringValue == 8: {% if internalStringValue == 8 %} TRUE {% else %} <font style="font-weight:bold;color:red">FALSE</font> {% endif %}<br/>
if (internalStringValue == 8): {% if (internalStringValue == 8) %} TRUE {% else %} <font style="font-weight:bold;color:red">FALSE</font> {% endif %}<br/>
if internalStringValue == "8": {% if internalStringValue == "8"  %} TRUE {% else %} <font style="font-weight:bold;color:red">FALSE</font> {% endif %}<br/>
if (internalStringValue == "8"): {% if (internalStringValue == "8") %} TRUE {% else %} <font style="font-weight:bold;color:red">FALSE</font> {% endif %}<br/>


<hr>
{% assign internalDecimalValue = 8.21 %}
<b>Internal Decimal Value: __ {{internalDecimalValue}} __</b><br/><br/>

if internalDecimalValue == 8.21: {% if internalDecimalValue == 8.21 %} TRUE {% else %} <font style="font-weight:bold;color:red">FALSE</font> {% endif %}<br/>
if (internalDecimalValue == 8.21): {% if (internalDecimalValue == 8.21) %} TRUE {% else %} <font style="font-weight:bold;color:red">FALSE</font> {% endif %}<br/>
if internalDecimalValue == "8.21": {% if internalDecimalValue == "8.21"  %} TRUE {% else %} <font style="font-weight:bold;color:red">FALSE</font> {% endif %}<br/>
if (internalDecimalValue == "8.21"): {% if (internalDecimalValue == "8.21") %} TRUE {% else %} <font style="font-weight:bold;color:red">FALSE</font> {% endif %}<br/>


<hr>
{% assign internalGuid = user.Id %}
<b>Guid: __ {{internalGuid}} __</b><br/><br/>
if internalGuid == user.Id: {% if internalGuid == user.Id %} TRUE {% else %} <font style="font-weight:bold;color:red">FALSE</font> {% endif %}<br/>
if (internalGuid == user.Id): {% if (internalGuid == user.Id) %} TRUE {% else %} <font style="font-weight:bold;color:red">FALSE</font> {% endif %}<br/>
if internalGuid == "5434435c-5527-f011-8c4d-002248b0b61d": {% if internalGuid == "5434435c-5527-f011-8c4d-002248b0b61d" %} TRUE {% else %} <font style="font-weight:bold;color:red">FALSE</font> {% endif %}<br/>
if (internalGuid == "5434435c-5527-f011-8c4d-002248b0b61d"): {% if (internalGuid == "5434435c-5527-f011-8c4d-002248b0b61d") %} TRUE {% else %} <font style="font-weight:bold;color:red">FALSE</font> {% endif %}<br/>

<hr>
{% assign internalIntValue1 = 1 %}
{% assign internalIntValue2 = 1 %}
<b>Internal Int Value 1: __ {{internalIntValue1}} __</b><br/>
<b>Internal Int Value 2: __ {{internalIntValue2}} __</b><br/><br/>

if internalIntValue1 == internalIntValue2: {% if internalIntValue1 == internalIntValue2 %} TRUE {% else %} <font style="font-weight:bold;color:red">FALSE</font> {% endif %}<br/>
if (internalIntValue1 == internalIntValue2): {% if (internalIntValue1 == internalIntValue2) %} TRUE {% else %} <font style="font-weight:bold;color:red">FALSE</font> {% endif %}<br/>

<hr>
<b>Combined conditions</b><br/><br/>

if internalDecimalValue = 8.21 and internalIntValue = 8: {% if internalDecimalValue == 8.21 and internalIntValue == 8 %} TRUE {% else %} <font style="font-weight:bold;color:red">FALSE</font> {% endif %}<br/>
if (internalDecimalValue = 8.21) and internalIntValue = 8: {% if (internalDecimalValue == 8.21) and internalIntValue == 8 %} TRUE {% else %} <font style="font-weight:bold;color:red">FALSE</font> {% endif %}<br/>
if (internalDecimalValue = "8.21") and internalIntValue = 8: {% if (internalDecimalValue == "8.21") and internalIntValue == 8 %} TRUE {% else %} <font style="font-weight:bold;color:red">FALSE</font> {% endif %}<br/>

Leave a Reply

Your email address will not be published. Required fields are marked *