Skip Navigation

[Resolved] Don’t display entire Layouts row if empty

This thread is resolved. Here is a description of the problem and solution.

Problem:
Client wants to conditionally display (or not) entire rows in Layouts.

Solution:
This is not currently supported, though we have a feature request for this.

You can achieve this by adding a specific class or ID to the row in question and adding another Visual Editor cell in the Layout with a style element that is added subject to the required condition, like so:

[wpv-conditional if="some condition"]
<style type="text/css">
#layout-row-unique-id {
  display: none;
}
</style>
[/wpv-conditional]
This support ticket is created 6 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 3 replies, has 2 voices.

Last updated by Nigel 6 years, 5 months ago.

Assisted by: Nigel.

Author
Posts
#916511
Screen Shot 2018-06-22 at 09.11.48.png
Screen Shot 2018-06-22 at 09.11.34.png

Tell us what you are trying to do? I am trying to hide a row if it is empty. I know how to conditionally check if a field is empty, however this only applies to the actual contents of the row. I have a row that has a full-width background set, which looks great when the row is filled, however when the row is empty, the background still appears. I was wondering if there was a way to hide an entire row, rather than just a field when it is empty.

Is there any documentation that you are following? I was following the conditional output documentation as well as the one for checking for non-empty fields. However, this only seems to apply to fields, rather than entire rows.

Is there a similar example that we can see? Screenshots attached.

What is the link to your site? hidden link at the bottom the yellow testimonial row is empty on this page, but being used here: hidden link

#916605

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Andy

We have a feature request to add conditional display of rows and cells in Layouts, but it is not currently possible.

However, as a workaround, you should note that if you add a Visual Editor cell and include a conditional shortcode then you can include any valid HTML inside the condition which will or will-not be printed in the final page depending on the condition.

So you could include a style tag with a simple CSS rule to hide the row in question (you may need to add an ID or class to it to use as your CSS selector) inside your conditional shortcode.

#917990

Hi Nigel,

Not sure I entirely understand the workaround. Let's say the yellow full-width row has the id 'custom-layout-testimonial'
I then have a conditional shortcode in a cell within that row that displays a testimonial if the field is not empty.
I'm now not sure how I can get the parent row to be hidden within that conditional shortcode.

#918225

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

I had in mind something like this:

[wpv-conditional if="some condition"]
<style type="text/css">
#custom-layout-testimonial {
  display: none;
}
</style>
[/wpv-conditional]

The style to hide the row will only get added to the page if your condition is met.

There is only one drawback I'm aware of, namely validation. I don't think styles in the body are strictly valid, although that is due to change (you can Google that to clarify if it is a concern).