Search code examples
fat-free-framework

how to check if a variable is defined in hive from within the view?


I'd like to setup a <check if='...'> where the if statement is defined on a param being defined. Is there a way to access this directly using the view?


Solution

  • You can use the variable on the if condition, it works:

    <check if="@doesnotexist">
      <true>The variable exists (?!)</true>
      <false>The variable does not exist</false>
    </check>
    

    This is possible because when you try to retrieve a value from the F3 Hive, it returns NULL when the key does not exist. Per documentation, NULL is considered false for this verification:

    An F3 expression inside an if attribute that equates to NULL, an empty string, a boolean FALSE, an empty array or zero, automatically invokes <false>