Referencing non-loaded collection in "IF" breaks data loading

Hello,
I have the following 2 pages which have the same data with a slight difference:

  1. Public Page: Show data from a cached XANO collection
  2. Editor Page: This is where the page editor can modify things and they need to see updates directly. Therefore, this is another collection that would only load for the editor/creator.

I am using a simple IF(page=“Editor”, load non-cached collection, load public cached collection).

The problem is that when I use this code, the code breaks down and no data is fed into collection list in the public page because “Non-cached” collection is not loading since it only loads in the editor page.

I was wondering if there is a way around this because I don’t want to have to load the non-cached collection too.

Attached is a sample formula fed into collection items.
Screenshot 2023-07-30 at 7.33.30 PM

the if formula evaluates both the options regardless. When you need to skip the evaluation of one block you need to switch to javascript mode and use a if/else statement.

1 Like

Thanks for your response. But this doesn’t make sense, it should evaluate the IF condition but not try to evaluate the content of the condition if its not met?
Doesn’t seem like an intended behavior and honestly having to switch to JS for such trivial matter defeats the purpose for me :sweat_smile:.

it does make a lot of sense and it is expected behaviour. Nocode formulas are javascript functions, therefore their parameters must be evaluated when executing the function.
This is a common misunderstanding (look here, here and here)
A javascript if/else statement has the behaviour you are looking for and it is very easy to use. The nocode equivalent in weweb is a workflow with if/else split.

Thanks for your clarification. Being a NoCode function, I assumed it would allow us to check conditions without having such a requirement of checking the content as well.

While having to use an IF/Else is logical and I have used it in PHP before for example, it still requires some coding knowledge (hopefully the Ai can help with this a bit).

I was wondering if you have an example showing how a collection or data is returned in this case? For example, would defining/accessing the global variable if a collection and then return $collection_var within my condition works?

Thanks!

there is an example here
If you click on variables/collections the right code gets inserted in the same way you do it with the nocode formulas. You can even use other nocode formulas.

1 Like

Great, will give this a go. Many thanks!

1 Like