I have a page that has about 30 queries on it. But on page load I really only need to load 4 or 5 of them depending on a URL Parameter value.
For example if URL Parameter = 1 then I only need three of the queries to run. If URL Parameter = 3 I need a different set of server connect queries to run.
Is there a way to only run queries based on a URL parameter? I don’t need to run all 30 queries on page load.
Something like this might do it: <dmx-serverconnect id="serverconnect1" dmx-bind:url="query.load==1?'dmxConnect/api/myFolder/myAPI.php':''"></dmx-serverconnect>
You can also do it this way round: dmx-bind:noload=(condition) ? 'noload' : ' '
You can nest ternary operators - that might do what you want. With a lot of conditions, it might get cumbersome and difficult to work with. I would probably work on the expression in a text editor and format it while working on it. Nested ternary operators result in pretty horrible code.
There might be a better way to achieve what you want.
Some other ideas you could explore @brad -setting the SC’s to not auto-load and then using Flows to fire the ones you need based on url params. You could prob use variables, too and onChange dynamic event run certain SC’s.
There will be a correct way to do this but again these might work.
You should use conditional regions and not just show/hide.
The difference is that conditional regions (dmx:if) never render at all if the condition is not met. Also their children like nested server connects are never rendered and execute.
While regular show/hide (dmx-show/dmx-hide) just toggles the css visibility but the contents is still rendered and executed.
So when you have large regions that you don’t want to render always use conditional region. It will be also much faster in performance.
Inside the flow, use condition to identify the query param value, and add a run step which would load all required SCs.
In case the flow does not capture the query param value correctly, add a wait as the first step. This could happen due to timing issue where param does not have the value yet, and flow has executed before that.
Another option, in case you have at least one SC that load every time.
Keep all server connects as noload.
On success of this SC, use ternary operator to identify param value and load relevant SCs.
Update: Checking the dev console it does appear that the proper actions are being executed. But they are returning no data? Why would they not return data?
The actions are executing properly (getting 200 status in console) just not returning any data. Remove the conditional region and the data returns as it should.
but have you tried re selecting the data with the new dynamic path I just tried this myself and it works perfectly, if you have a a server connect that you just move to a conditional region the data is still returned but not displayed if you then update the data path what your displaying it works.
This was a bit more work than using conditional regions but it worked like a charm! Now it only loads the actions I need and the page and data load lightning quick.
Results achieved! I always forget about flows. They are powerful. Thank you again!
Leaving this as a bug though as Conditional Regions should have worked.