Is it possible to not show a layout on the front page if there is not content in it ? The problem is that these layouts are adding sections and rows to the page (see pictures) and consequently adding a big white space.
We would have to change the template every time the user modify the object. I was looking for something more dynamic.
I found a halfway solution for this. I check in the layout controller if the data in content type is empty or not . If it is empty I simple tell to not render the components.
Hi, @olivr3! It sounds like you figured out almost the same method I use. Whereas I understand that you check this in the controller, I do it in the Thymeleaf-template. (Mostly using “th-if” or “th-each”, depending on if there can be more than one item or not)
The reason I choose to do it in the template, is that I might have data for one part of the layout, but not another.One example might be if you have an “aside-column” that is empty, but the main content is there. If you check in the controller, you have to choose all or nothing. (Or have multiple template files that you choose from in the controller.
If I remember correctly, it will also be useful to do a check to see if you are in admin mode, as I believe you might break the drag-and-drop-functionality if you don’t print the HTML when there are no data.
I have a situation which there are two parts inside a layout.
two-column layout
— left region
left part
— right region
right part
I also use ‘th-if’ to check if the left and right part are both empty. The layout is rendered on the page if any of these parts have content on them.
This approach solved the problem of rendering empty divs to the page, however I was looking for something more dynamic to it. The logic can get quite big if you have a lot of data to check. Imagine if you use this same layout ‘two-columns layout’ to render more than 1 content type to page. You would have to create a logic to verify each content type as they have different data.