I never used the itchycode conditions, but it seems like the bricks conditions just don’t honour true/false as boolean values. I think you need to use actual booleans instead like 1/0.
I think what’s happening though is this. Imagine that true is a bool so it equals 1, but if true is a string it equals the literally word ‘true’. So I think what bricks is doing is it’s comparing true (bool) to true (string), which is not equal.
This is what I would consider a potential bug. It might be worth creating a bug report about it.
In PHP, everything different from 0 (zero) or alike (empty stuff, “0”, etc.) is true, so you can use 1 and 0 for replacement of true and false respectively.
And I agree with @cmstew that the string true must be interpreted by Bricks as the actual string “true”, and that’s normal, since this string has to be potentially usable in conditions value.
The result of dynamic tag echo function {echo:is_front_page} will return string. If the result of your function is true, will be string 1. If the result of your function is false, will be empty string
The compare value we input always interpreted as string
Scenario 1:
If this is in front page.
Will compare string 1 with string true.
The element will be hidden, because result is false.
If this is not in front page.
Will compare empty string with string true
The element will be hidden, because result is false
Scenario 2:
If this is in front page.
Will compare string 1 with string 1
The element will be shown, because result is true
If this is not in front page.
Will compare empty string with string 1
The element will be hidden, because result is false
Scenario 3
If this is in front page.
Will compare string 1 with string 0
The element will be hidden, because result is false
If this is not in front page.
Will compare empty string with string 0
The element will be hidden, because result is false
Conclusion, boolean type compare is not what we think in php boolean compare in current Element Condition.
If using echo dynamic tag
use == and empty compare value for a false expected return boolean function
use != and 1 value for a false expected return boolean function (easier as explained by yankiara)
use == and 1 value for a true expected return boolean function
do not use 0 because false expected boolean return function will only return empty string
PS: Please correct me if I am wrong. I just tested for a few scenarios. Hope Bricks team can help on this.
@itchycode It seems you inverted shown and hidden, since if comparison result is true, element is shown.
But otherwise I agree, and I was clearly wrong writing 0 could be used as false.
String zero (“0”) evaluates as FALSE in PHP, but in this case it cannot be used because return value is empty string, whis is different from “0”, as a string.
(In other words, my comprehension is that both empty string and zero string evaluate to false as boolean, but they are not identical if compared together as strings!)
So, my conclusion is that I will use “== 1” for true and “!= 1” for false, which seems more consistent and easier to remember
By the way now I remember it is exactly what I used to do with Oxygen (same string-based values to compare)
It’s just first iteration of conditions. More improvements to come. Once the Conditions API is out adding our own compare types and conditions won’t be difficult. Next few updates should refine it a lot.