PHP Conditional Region Approach

I have a website structured with various modules such as Gallery, Text Intro, and Product Detail. These modules are dynamically selected from a database to populate each page.

For instance:

Page 1:

  • Gallery
  • Product Detail

Page 2:

  • Text Intro
  • Project Detail

This setup relies on a repeat region that includes conditional regions based on the modules stored in the database. However, this approach results in each repeat region containing nine conditional regions, often leading to the creation of numerous empty divs.(Conditional Regions)

I hope this clarifies the situation. So whats the best approach?? I am using php.

For each Item on database validate every module.

Hi Juan,

When you say creation of numerous empty divs, are you referring to empty divs in the UI or in the html?

In the html

In AC2, the source html code appears for all elements.

I got that but the problem is that for the CMS I am trying to achieve for one div need to I need 9 conditional regions. So it creates 8 divs unnecessary.

Or any alternative for PHP like nodejs?

<% if (user) { %>
  <h2><%= user.name %></h2>
<% } %>

If you're referring to additional divs showing in the UI, then wrap the conditional div in another div with dmx-show. This way the empty conditional divs do not appear in the UI (the divs will still appear in the html).

So, in your case, if you add a div with code like this dmx-show="id_module==1", then it will hide that empty conditional div in the UI.

I totally get that. But is now what I am looking for. I am looking that when the condition is not met. Don’t add the div not in the UI or the source code.

Adding a div in the source code doesn't impact the code functionality. I may be wrong, but I don't believe it's possible to remove the source code for conditional divs in AC2.

For the div to show / hide in the UI, try wrapping the conditional div with dmx-show example I posted before. There may be other ways to achieve this, but this is my approach when I'm including any conditional divs in the code.

We are also working on providing PHP server side rendering, data bindings and conditional rendering just like we have for NodeJS

Hope to have available soon but will be probably during the Wappler 7 beta cycle after our summer break.

3 Likes

This will be awesome. Is not that I don’t want to move to nodejs. The big problem is that some of our clients already own a server and is hard to convince them to move to a new service. So we need to keep with php.

Also de SEO stuff will be easier.

2 Likes

See:

1 Like

Hello @George is any progress on this?? All weeks I download the new beta hopping this is implemented. Thanks a lot in advance.