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.

3 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?

Hello do you find the way to do it?? I still on the same point.

There are template functions coming to PHP that will allow you to access data from a serverconnect action that can be included on the page. Can't say how long the implementation will take but I already did some preparations in the PHP code for it.

Here a sample of the current experimental implementation, this can change in the future.

<!-- tell serverconnect we are in a template -->
<?php define('TEMPLATE', true); ?>
<!-- simply require the serverconnect action, it will run directly -->
<?php require('dmxConnect/api/myaction.php'); ?>
<!-- inserting data from a serverconnect expression -->
<?=_parse('expression')?>
<!-- using expression in a if statement -->
<?php if (_parse('expression') == 1) { ?>
3 Likes

What does mean expression? Do you have any example? Like any value from the recordset?

<?=_parse('expression')?>

Yes, it parses serverside expressions like query1.data. You can access data from the serverconnect that was included on the page.

2 Likes

As soon this is available will be amazing. Open a lot of possibilities for PHP. Maybe conditional regions won't be used as much as now.

Does we have any notice for this?? Thanks a lot @George

We will be adding this functionality during the Wappler 7 beta cycle

4 Likes

Are we now on the beta cycle??

I am testing the 7 and looks amazing I find some tweaks that I will be posting to improve. Thanks a lot.

Great!
Manual PHP layout using routing is fast, but not as fast and intuitive as NodeJS.
It's always very difficult to start all over again when routing doesn't work anymore after many changes to the page.

Friendly Bump.