Avoid rendering an HTML element via server-side condition data

<%if (serverdata) { %>
<p>Do not render this paragraph</p>
<% }

The condition(as a good condition) won’t evaluate always to the same value.

Imagine I have a set of cards rendered via an AC repeating row component.

Each card will have different html depending on server data. I don’t want to show/hide in the DOM. I want to avoid altogether that it is inserted in the DOM.

Any hints @patrick?

This is not going to be an easy one right @patrick?

I’ve been checking the core files and I can’t possibly think of a way to accomplish this with the current set of features available. I miss additional horsepower when working with templates.

You can use all features from ejs templates, so conditions should work.

<% if (_('condition')) { %>
<p>Do not render this paragraph</p>
<% } %>

Use _('expression') to evaluate server connect expressions.

2 Likes

Yes, ejs conditions do work. But the data available will be only of two types. Static data I add to routes.json or the output of a SC assigned to the route. As expected of course.

However the SC uses parameters to filter so if I load the page: “Undefined binding(s) detected for keys…”
It seems that current functionality is limited or geared towards meta tags and getting data that doesn’t depend on query parameters.

Query parameters should be supported, how do you use them?

Please note that in NodeJS there is a difference between query parameters and path parameters. Lets say you have a route path like /page/:id, you get the id with $_PARAM.id. Query parameters like $_GET.id will only get parameters after the ?, like /page?id=1.

I had one of those days. Thanks Patrick!

Hey @patrick,

I know it’s been a long time ago and this thread is NodeJS related but searching didn’t bring something that can help me on it (or I haven’t found anything yet)…

Is there a workaround in php mode for accessing wappler SC & AC actions and control conditional rendering elements?
For example:

<?php if ( ***serverconnect_Action.identity == 1*** ) { ?>
html elements here
<?php } ?>

Is any help on this?? I am in the same point?