This is somewhat linked to this post: DC Looper API - How to access value from key that has dot syntax - please see the login detail in the Secure Note in that post.
How would I use the Conditional function to hide an element if there is no record in the API fetched data.
With ACF - I can create a condition where it can check a key and see if its empty or not.
Whereas with an API JSON file, I don’t know how to make the condition work as the API has no data/key whatsoever.
For example: (the looper provider uses the “data” as the Data Key in the object
“data”: [
{
“Courses”: {
“Course_Name”: “course 1”,
“ID”: “118644000003209497”,
},
“ID”: “118644000004210488”,
“Course_Serial_Number_Autofill”: “100”,
“Start_Date”: “03 July 2024 09:30”,
“End_Date”: “03 July 2024 14:30”,
“Event_Cancelled”: “false”
},
{
“Courses”: {
“Course_Name”: “course 2”,
“ID”: “118644000003209497”,
},
“ID”: “118644000004210492”,
“Course_Serial_Number_Autofill”: “200”,
“Start_Date”: “03 July 2024 09:30”,
“End_Date”: “03 July 2024 11:30”,
“Event_Cancelled”: “false”
},
{
“Courses”: {
“Course_Name”: “course 3”,
“ID”: “118644000001252015”,
},
“ID”: “118644000004210474”,
“Course_Serial_Number_Autofill”: “300”,
“Start_Date”: “05 July 2024 10:00”,
“End_Date”: “05 July 2024 12:00”,
“Event_Cancelled”: “false”
}
Works
Text element 1(“course is available”): Condition = 100 is {{dc:looper:field key=“Course_Serial_Number_Autofill”}} = matches with ‘course 1’ so it shows the text element saying: “course is available”. if no matching course, this element is hidden.
DOESNT WORK
Text element 2(“course not available”): Condition = 400 is not {{dc:looper:field key=“Course_Serial_Number_Autofill”}} = doesnt match with any course, so shouldnt it show the text element? I also tried “not in” but that doesnt work too.
I think it’s because there are no record whatsoever to compare the conditions to. So if there are no record, how is it going to compare?
But if that is true - how can I show a message that says ‘course not available’ if there are no record from the pulled API data?
The logic is: if there are matching courses, text element 1 should show. if there is no matching courses, text element 2 should show.
Maybe there is a function on Cornerstone that I don’t know. Please point me to how I can solve this.
Thank you!