Skip Navigation

[Resolved] Hide field when empty using conditional HTML

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

Problem:

I've managed to get a field to only show if NOT empty.

The trouble is that it's not outputting the field data, just the code as is written (i.e. [types field='display-date-to.... etc.) in the front end.

Solution:

The client have found that the issue was the Raw HTML block wasn't displaying correctly. When changed to a WP Custom HTML block, it worked as intended!

Relevant Documentation:

https://toolset.com/documentation/user-guides/conditional-html-output-in-views/#debugging-conditional-output-in-views

This support ticket is created 6 years, 1 month 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 6 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#1159050

Tell us what you are trying to do? Hide a 'Date to' field when empty

Is there any documentation that you are following? Yes - https://toolset.com/documentation/user-guides/conditional-html-output-in-views/ and https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/

Is there a similar example that we can see? As above

What is the link to your site? sobell.adstest.co.uk

I've managed to get a field to only show if NOT empty using the following:

[wpv-conditional if="( NOT(empty($(wpcf-display-date-to))) )"]{!{types field='display-date-to' style='text' format='D d M, Y'}!}{!{/types}!}[/wpv-conditional]

The trouble is that it's not outputting the field data, just the code as is written (i.e. {!{types field='display-date-to.... etc.) in the front end.

I'm using the code in WPBakery in a raw HTML box.

I've removed the conditional code now whilst I'm rectifying the issue but you can see the field as an example on this page - hidden link

You'll see that the To: field label is showing even though the field is empty.

I'm sure this is something simple that I'v missed and I look forward to your thoughts.

Kind regards
James

#1159358

Hello,

There is a extra ")"in your shortcodes, please try to modify it from:

[wpv-conditional if="( NOT(empty($(wpcf-display-date-to))) )"]{!{types field='display-date-to' style='text' format='D d M, Y'}!}{!{/types}!}[/wpv-conditional]

To:

[wpv-conditional if="( NOT(empty($(wpcf-display-date-to))) "]{!{types field='display-date-to' style='text' format='D d M, Y'}!}{!{/types}!}[/wpv-conditional]

And you can manually debug the wpv-conditional shortcode by adding attribute debug="true", see our document:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/#debugging-conditional-output-in-views

#1159711

Hi Luo,

I tried removing that but it didn't fix the issue. I finally found that the issue was the Raw HTML block wasn't displaying correctly. When I changed to a WP Custom HTML block, it worked as intended!

Many thanks for your help.

Kind regards
James

#1160275

Thanks for sharing the solution, it will help other users.